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

Fallback mapping only for output #307

Open
apascual opened this issue Jul 21, 2021 · 5 comments
Open

Fallback mapping only for output #307

apascual opened this issue Jul 21, 2021 · 5 comments

Comments

@apascual
Copy link

I noticed that the fallback mapping is only used for the output and not for the input. This creates some troubles like exporting a set of files that cannot be inserted back because incorrect language codes are resolved.

It also looks like so far the only purpose of the fallback mechanism is to support the Android regional codes that everybody use for simplified and traditional Chinese.

And then my question is, shouldn't the language code fix for Chinese be inside the Android formatter instead?

@sebastianludwig
Copy link
Collaborator

It's been a while since I worked on this part but IIRC the fallback is applied to all formatters, so also Apple would use zh-Hant before falling back to en, right?

This creates some troubles like exporting a set of files that cannot be inserted back because incorrect language codes are resolved.

What's your workflow? When/how/why do you re-import platform specific formats? Would specifying --lang work for you? What languages do you maintain in the Twine file and what are your desired output languages?

@apascual
Copy link
Author

Hi @sebastianludwig,

It's been a while since I worked on this part but IIRC the fallback is applied to all formatters, so also Apple would use zh-Hant before falling back to en, right?

Correct, but in practice, with the existing default configuration it feels like it is there just to fix the problem with Android not supporting zh-Hans / zh-Hant.

What's your workflow? When/how/why do you re-import platform specific formats? Would specifying --lang work for you? What languages do you maintain in the Twine file and what are your desired output languages?

Our configuration is simple and I think quite typical. One (twine) file with multiple languages including zh-Hans and zh-Hant.

Four different actions that we run:

  1. Export iOS strings: ✅ It does not need to use the fallback mechanism since the language codes in the twine file and the project are a perfect match.

  2. Export Android strings: ✅ It uses the fallback mechanism to match zh-Hans -> zh-CN and zh-Hant -> zh-TW.

  3. Export strings for translation: ⁉️ All the untranslated strings are exported at the same time using generate-all-localization-files into a new folder. There is no fallback mechanism in place here and using Android format produces folders called values-zh-rHans and values-zh-rHant which are incorrect in Android.

  4. Consume translations: ❌ Importing translations with the folders mentioned above will not work as the Android formatter parser expects two characters for the regional code part instead of four. Manually renaming those folders into values-zh-rCN and values-zh-rTW will not work either because it will insert those strings as new languages (zh-CN/zh-TW) instead of match the existing ones (zh-Hans/zh-Hant).

And that is why I think that the problem of Android not supporting the standard codes for simplified/traditional Chinese should be addressed inside the Android formatter instead of using the generic fallback mechanism, that is also only one way (exporting).

And yes, manually incorporating each language file with the --lang parameter would probably work, but then we cannot use consume-all-localization-files to directly insert what we get back from translators.

@scelis
Copy link
Owner

scelis commented Jul 26, 2021

Yes, I believe the current Android formatter does not support the newer BCP 47 support introduced in Android 7.0. It would be nice to add support for that and then remove the older fallback mechanism. Does this sound correct to you?

@apascual
Copy link
Author

Yes, I believe the current Android formatter does not support the newer BCP 47 support introduced in Android 7.0. It would be nice to add support for that and then remove the older fallback mechanism. Does this sound correct to you?

@scelis Yes, that would work. If there would be support for BCP 47, then Android could use the modern language codes and no need to use fallbacks.

The abstract formatter (and maybe other parts of Twine) would also need to support BCP 47:

LANGUAGE_CODE_WITH_OPTIONAL_REGION_CODE = "[a-z]{2}(?:-[A-Za-z]{2})?"

@pastk
Copy link

pastk commented Jan 3, 2022

  1. Export strings for translation: All the untranslated strings are exported at the same time using
    generate-all-localization-files into a new folder. There is no fallback mechanism in place here and
    using Android format produces folders called values-zh-rHans and values-zh-rHant which are incorrect in Android.

I second that.
We have to use a custom patch to rename zh-Hans to zh and zh-Hant to zh-rTW.

BCP-47 support sounds good, but wouldn't that mean that android formatter will be Android 7.0+ only? What about earlier versions? I think there should be a fallback mechanism anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants