Skip to content
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

BUGFIX: Restore XLIFF translation fallback #1094

Merged
merged 2 commits into from Nov 11, 2017

Conversation

fritjofbohm
Copy link
Contributor

This modification fixes the translation fallback mechanism and the ability to read regionalized language variants.

Issues fixed:

  • Translation fallback did not work. Neos.Flow.i18n.fallbackRule.order was ignored when looking for XLIFF files
  • When using a regional Neos.Flow.i18n.defaultLocale (e.g. de_AT for an Austrian version of de), XLIFF files were never read from a directory with the full defaultLocale name, but only from the base language directory. In the example, files in Packages/Application/Vendor.Package/Resources/Private/Translations/de_AT were never read, only fromPackages/Application/Vendor.Package/Resources/Private/Translations/de.

@albe
Copy link
Member

albe commented Oct 17, 2017

Thanks, this makes sense! Left two comments. Also, this should probably be targeted lower (3.3 even as it's LTS and still in bugfix support).

if (is_dir($translationPath)) {
$this->readDirectoryRecursively($translationPath, $parsedData, $fileId, $package->getPackageKey());
$localeChain = $this->localizationService->getLocaleChain($locale);
foreach (array_reverse($localeChain) as $localeChainItem) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not so obvious why the locale chain needs to be walked in reverse, can we maybe add a small explanatory comment?

@@ -87,26 +94,29 @@ public function initializeObject()
*/
public function getMergedFileData($fileId, Locale $locale): array
{
if (!isset($this->files[$fileId][$locale->getLanguage()])) {
if (!isset($this->files[$fileId][$locale->__toString()])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the localization service we use (string)$locale instead. Would be nice to have that in line

@albe
Copy link
Member

albe commented Oct 17, 2017

Thanks! Can you also rebase this on 3.3, since simply changing the base won't work in this case.

@fritjofbohm
Copy link
Contributor Author

This file is new in 4.2, so we can't rebase this to 3.3. Before 4.2, Flow used a different approach in loading XLIFF files (see #894)

@albe
Copy link
Member

albe commented Oct 17, 2017

Ah yes, of course! My bad :) Then this just needs a rebase on 4.2, which should be pretty easy.

@@ -87,26 +94,30 @@ public function initializeObject()
*/
public function getMergedFileData($fileId, Locale $locale): array
{
if (!isset($this->files[$fileId][$locale->getLanguage()])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm feels wrong to me to rely on the magic __toString() method, maybe add a getIdentifier or getLocaleIdentifier method and use that instead? __toString() could do that same then of course..

but maybe that's just me..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a getIdentifier() method in \Neos\Flow\I18n\Locale is generally a good thing, but it's also a medium change to Flow if you consequently replace each Locale string cast with the new method. This is just a humble bugfix ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, seems like it's used a bunch of other places in the code so guess someone meant to use that way.. nvm then

@fritjofbohm
Copy link
Contributor Author

fritjofbohm commented Oct 18, 2017

OK, I did a rebase of this stuff on 4.2. Please let me know if I did it right.

@albe albe changed the base branch from master to 4.2 October 18, 2017 13:31
@albe
Copy link
Member

albe commented Oct 18, 2017

Seems a couple of unrelated commits sneaked in. Try pulling latest 4.2 branch, then (force) rebase in interactive mode on that and skip all but your two commits (if there are still any other).

This modification fixes the translation fallback mechanism and the ability to read regionalized language variants.

Issues fixed:

* Translation fallback did not work. `Neos.Flow.i18n.fallbackRule.order` was ignored when looking for XLIFF files
* When using a regional `Neos.Flow.i18n.defaultLocale` (e.g. `de_AT` for an Austrian version of German `de`), XLIFF files were never read from  a directory with the full `defaultLocale` name, but only from the base language directory. In the example, files in `Packages/Application/Vendor.Package/Resources/Private/Translations/de_AT` were never read, only `Packages/Application/Vendor.Package/Resources/Private/Translations/de`.
… and add comment

* `$locale` is now cast the way it is in `\Neos\Flow\I18n\Service`
* Added a small comment why the locale chain is reversed
@fritjofbohm
Copy link
Contributor Author

Next try. Better this time?

Copy link
Member

@albe albe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good now :) Thanks!

@kitsunet kitsunet merged commit 0893f4b into neos:4.2 Nov 11, 2017
@fritjofbohm fritjofbohm deleted the fix-xliff-language-fallback branch December 7, 2017 16:12
ComiR pushed a commit to ComiR/flow-development-collection that referenced this pull request Aug 17, 2018
…back

BUGFIX: Restore XLIFF translation fallback

This modification fixes the translation fallback mechanism and the ability to read regionalized language variants.

Issues fixed:

* Translation fallback did not work. `Neos.Flow.i18n.fallbackRule.order` was ignored when looking for XLIFF files
* When using a regional `Neos.Flow.i18n.defaultLocale` (e.g. `de_AT` for an Austrian version of `de`), XLIFF files were never read from  a directory with the full `defaultLocale` name, but only from the base language directory. In the example, files in `Packages/Application/Vendor.Package/Resources/Private/Translations/de_AT` were never read, only from`Packages/Application/Vendor.Package/Resources/Private/Translations/de`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants