New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n: Set locale data per domain #5168
Comments
IMO, a fallback to the "default" domain when the key doesn't exist in the given domain would also be a good feature for this. |
Hi @tpaksu , can you elaborate on what you're expecting? Are you referring to something like a specialized language code falling back to the more generalized form? (For example, with a complete set of strings in I think this should be possible already, as long as you merge the string data before calling Something like: const fr = { '': { lang: 'fr' }, 'Why?': [ 'Pourquoi?' ], 'Title': [ 'Titre' ] };
const frCA = { '': { lang: 'fr-CA' }, 'Why?': [ 'À cause?' ] };
wp.i18n.setLocaleData( lodash.assign( {}, fr, frCA ), 'mydomain' );
wp.i18n.__( 'Why?', 'mydomain' )
// "À cause?"
wp.i18n.__( 'Title', 'mydomain' )
// "Titre" Is that what you have in mind? Otherwise, it would be best to create a separate issue where we can discuss an implementation which supports your needs. |
Hi @aduth, I thought that if someone uses the domain component-wise, such as having the
will show |
But, of course this may better suit into the may contain an extra parameter for the may be extended with: entry = this.data[ fallback ][ key ];
if ( entry && entry[ index ] ) { |
Oh, I think I understand what you're suggesting now. I'm a bit reluctant to revise the argument signature, largely because it is meant to precisely mimic the equivalent function in GNU gettext. But I wonder if there might be some option around the
Example on how that can be achieved today: |
Yes, about onMissingKey, I opened a new feature request today, #18392 as it can't be accessed from outside. If it was available, it was the best place to hook on to. |
The current implementation of the JavaScript
wp.i18n.setLocaleData
and PHPgutenberg_get_jed_locale_data
functions assume to set a singular blob of Jed data, and do not accommodate multiple domains.We should seek to change this in two ways:
gutenberg_get_jed_locale_data
should not set the default domain, and in-fact may only return just the inner array currently represented as$domain => array(
:gutenberg/lib/i18n.php
Lines 25 to 27 in 1ca5f6c
wp.i18n.setLocaleData
should accept a domain argument, and merge strings for the given domain into the current (or a new) global Jed configuration:gutenberg/i18n/index.js
Lines 15 to 17 in 1ca5f6c
The text was updated successfully, but these errors were encountered: