Closed greatislander closed 3 months ago
This sounds interesting - I like the idea of supporting user-supplied localizations via the Wordpress interface, if this is the way Wordpress developers are used to handling localization.
Forgive my relative ignorance about WP development in the following comments / questions:
The flow of loading JSON message bundles for UIO ultimately results in Javascript objects on the UIO component containing the strings intended for use by the individual panels, so I believe we could write some custom Javascript for the plug-in that would replace this flow with the WP-based one you describe.
if wp_localize_script
expects to work with a JS object, we could craft something that would (in the plug-in) parse the various JSON message files and generate appropriate scripts from them, perhaps
At a high level, how would we expose the UIO strings for translation in the Wordpress interface? I've done localization work in Drupal ages ago, but never in WP.
I'm uncertain of how much effort this would be without some experimentation (a very generic statement, I know), but it sounds interesting
@waharnum Sorry for the slow response. Replies to your points below.
if
wp_localize_script
expects to work with a JS object, we could craft something that would (in the plug-in) parse the various JSON message files and generate appropriate scripts from them, perhaps
Since I wrote this ticket, WordPress has published a JavaScript localization package which should allow something like this (no PHP intermediary required):
import { __ } from '@wordpress/i18n';
module.exports = {
'slidingPanelShowText': __( '+ Show Preferences', 'uio' ),
'slidingPanelHideText': __( '- Hide Preferences', 'uio' ),
'showTextAriaLabel': __( 'Show Display Preferences', 'uio' ),
'hideTextAriaLabel': __( 'Hide Display Preferences', 'uio' ),
'slidingPanelPanelLabel': __( 'User Preferences', 'uio' )
};
At a high level, how would we expose the UIO strings for translation in the Wordpress interface? I've done localization work in Drupal ages ago, but never in WP.
You could then use this Babel plugin to generate a gettext POT file for localization. The WordPress plugin directory actually provides an interface for localizing plugins — see, for example, the translation page for Akismet. Since it looks like your plugin is not in the plugin directory, I'd recommend Transifex, which offers a free plan for Open Source (we use it at Pressbooks). I know there are other solutions out there as well. Hope this helps! And I'm happy to contribute a little time to this. It would be great to see User Interface Options localized/localize-able.
@greatislander UIO has been localize-able for quite some time, it's been the localization we've been lacking. :) We've recently published a number of localized translations for UIO based on work in the last year - you can see the Spanish ones in action at https://karisma-stories.floeproject.org/ and the bundles themselves are in https://github.com/fluid-project/infusion/tree/master/src/framework/preferences/messages and we're working on a language switcher panel that will expose them more easily to end-users.
I'm uncertain when we'll be able to update the plugin to make use of all that, but just updating as to the current status. Thanks for all the info about WP plugins - it's helpful in thinking about how we might improve the plugin further.
The project is no longer actively maintained and will be archived.
The way that WordPress handles localization for JS files is by creating an object with localized strings. So, for example, I'd use the following PHP code to register and localize a script:
Then, in JS, I can access the localized strings (
__( $string, $textdomain )
is the localization function) as follows:What I'm wondering is if there would be any interest in allowing User Interface Options (and this plugin) to load localized strings via JS objects instead of just by loading JSON message bundles as described here. This would allow the WordPress User Interface Options plugin (and other implementations, such as the one for Pressbooks that I've been slowly working away on) to support user-supplied localizations via WordPress methods.