-
Notifications
You must be signed in to change notification settings - Fork 93
Bundle does not work properly with new Intl ICU translations #452
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
Bundle does not work properly with new Intl ICU translations #452
Conversation
It will allow us to control if we want to use new ICU format (with suffixed domain with "+intl-icu") or format. Configuration has normalizer (making sure string is in lower case) and validator (making sure it's a string and either "" or "icu"). Setting `new_message_format: ""` we'll end up with new translations in container like: {domain}.{locale}.{ext}. Setting `new_message_format: "icu"` we'll end up with new translations in container like: {domain}+intl-icu.{locale}.{ext}. php-translation#300
Add new argument to converter methods to make sure we're able to recognize existing translations (and use correct domain - either standard or ICU format). In case translation is new we're going to use predefined format (using new configuration option new_message_format). php-translation#300
Let the default configuration overlap with Symfony configuration option default value. php-translation#300
Because of MessageCatalogue interface limitation we're using NSA to access raw messages data. Additionally because defines() method uses isset() were force to check raw messages data directly to check if key exits (translations from source collection are all set to NULL). php-translation#300
We have: 1. Source message domain. 2. Target message domain. 3. Result message domain (this is tied to 2 of the above). This solution assumes we'd always like to use ICU format (result message domain) if we use it in any of source or target catalogue. Additionally because of default NULL values in source catalogue (internal extractor design to set NULL for "target" when creating messages catalogue from source collection) we have to check if desired catalogue's messages field has a key (within requested domain) or not. Using MessageCatalogue::defines() would return false for catalogue without translation (NULL value). Lastly - make sure internal messages field utilised result message domain for consistency with result field. php-translation#300
Catalogue/CatalogueFetcher.php
Outdated
$messages = $currentCatalogue->all(); | ||
unset($messages[$domain]); | ||
$messages = NSA::getProperty($currentCatalogue, 'messages'); | ||
unset($messages[$domain], $messages[$domain . '+intl-icu' /* MessageCatalogueInterface::INTL_DOMAIN_SUFFIX */]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you don't use MessageCatalogueInterface::INTL_DOMAIN_SUFFIX
anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've placed commented out const to make sure everyone knows the source of the string.
Reason: BC.
Personally I'd use imports no problem; however I didn't want to touch any dependencies, so went with literal string.
Similar to this snippet (at line https://github.com/php-translation/symfony-bundle/blob/master/Catalogue/Operation/ReplaceOperation.php#L40):
if (\defined(\sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) {
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
} else {
$intlDomain = $domain;
}
(difference is I'd still try to recognise this format - not sure if it'd work though)
$intlDomain = $domain; | ||
} | ||
|
||
$intlDomain = $domain . '+intl-icu' /* MessageCatalogueInterface::INTL_DOMAIN_SUFFIX */; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, why you don't use MessageCatalogueInterface::INTL_DOMAIN_SUFFIX
anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as "above".
}) | ||
->thenInvalid('The "new_message_format" must be either: "" or "icu"; got "%s"') | ||
->end() | ||
->end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think naming this parameter use_icu_format
as a boolean is better here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now we have 2 formats; later we may have more (though with pace of changes and ICU capability I guess we'd have to wait for at least a decade to have something new).
It's just future proof option; however I do not have any problems with replacing this with a bool configuration.
One remark here - the name does not reflect the its nature (it may suggest all translations will be casted to ICU format; for now it just places new translations in ICU formatted file).
Hey @snpy , Thank you for working on this and sorry for the delays! Could you pull the latest changes from master to see tests are green here? Also, any pending work left here, or do you think this one is ready? |
@snpy could you at least check "Allow edits by maintainers" here, I'll try to rebase it myself to see if tests are green here |
@bocharsky-bw Hi, I will try to find some time to do it today or tomorrow. I don't want to rebase current branch as it was intentionally based on specific tag version. Will create new branch and rebase it (will also look into option you've mentioned). |
Hey Marek! Sure, do it when you can, it's not an urgent question. And thank you for the work you did so far on this! |
any word on this? Would love to use this bundle with ICU support |
Sorry, but I had chronically little time lately. |
is it still alive? |
Sorry; slipped my mind. |
Update `master` branch
e8c547e
to
04a1f1e
Compare
It will allow us to control if we want to use new ICU format (with suffixed domain with "+intl-icu") or format. Configuration has normalizer (making sure string is in lower case) and validator (making sure it's a string and either "" or "icu"). Setting `new_message_format: ""` we'll end up with new translations in container like: {domain}.{locale}.{ext}. Setting `new_message_format: "icu"` we'll end up with new translations in container like: {domain}+intl-icu.{locale}.{ext}. php-translation#300
Add new argument to converter methods to make sure we're able to recognize existing translations (and use correct domain - either standard or ICU format). In case translation is new we're going to use predefined format (using new configuration option new_message_format). php-translation#300
Let the default configuration overlap with Symfony configuration option default value. php-translation#300
Because of MessageCatalogue interface limitation we're using NSA to access raw messages data. Additionally because defines() method uses isset() were force to check raw messages data directly to check if key exits (translations from source collection are all set to NULL). php-translation#300
We have: 1. Source message domain. 2. Target message domain. 3. Result message domain (this is tied to 2 of the above). This solution assumes we'd always like to use ICU format (result message domain) if we use it in any of source or target catalogue. Additionally because of default NULL values in source catalogue (internal extractor design to set NULL for "target" when creating messages catalogue from source collection) we have to check if desired catalogue's messages field has a key (within requested domain) or not. Using MessageCatalogue::defines() would return false for catalogue without translation (NULL value). Lastly - make sure internal messages field utilised result message domain for consistency with result field. php-translation#300
…le into handle-icu-domain
We're now providing getter method name for new field.
Add new ICU messages domain. Make sure configuration is set to before-the-modification configuration. New messages will not be added to ICU domain. An additional tests must be run with new option set to ICU. This however may require functional tests refactor.
@bocharsky-bw Changes here should be ready for the review/testing. Thanks in advance. |
@bocharsky-bw One PHP-CS-Fixer suggestions as applied and one was fetched from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for finishing this!
Looks good to me for a minor release
Thank you for finishing it, Marek! |
Thanks for merging it. |
(Please ignore my ignorance if I should have followed PR guideline; PR was created in haste; if I should modify or redefine the PR please let me know and I'll fix it)
This PR is a proposition to handle ICU formats similarly as they are in Symfony internals.
The sanest way to deal with it is to stop using MessageCatalogue interface and look inside it with
NSA
package and determine manually if we should utilise ICU domain format or "normal" domain format.Additional this PR introduces
new_message_format
configuration that will allow us to control if we'd like to use ICU format for new messages or not.I guess for compatibility reason I should have set it by default to "" instead of "icu", but that can be easily fixed if this PR will be accepted only because of this BC issue.
The code itself was based on 0.12.3 tag instead of
master
in casemaster
changes require additional work.This should be fixing first issue described at #300 making bundle operational for translations kept in ICU formats.