chiyadev / genshin-schedule

🕑 Genshin farming scheduler
https://genshin.chiya.dev
MIT License
72 stars 17 forks source link

Use defaultMessage instead of id to translate #64

Closed ysc3839 closed 3 years ago

ysc3839 commented 3 years ago

There is still some entries with id. I put them in langs/static.json. I think we need a script to manage the translation files.

luaneko commented 3 years ago

Discord message link

I discussed about this PR on Discord with BiliGoldenWater who had some concerns about using automatic extraction.

Hashes are not descriptive of the message content

It's friendlier for translators when they see resinTitle instead of a hash like fxk59ds. The descriptive ID gives an idea of where the message is being used in the UI ("resin" and "title") which can be helpful.

Hash changes when the original text changes

If a message in the en-US localization changes, the message ID changes together which renders the translation of this message in all other localizations unusable and fall back to en-US until updated by the translators again.

Localization files should not be splitted

Having multiple files for a single localization (like en-US.json and static.json in this PR) makes it incompatible with online translation platforms.

Counterargument

This PR uses FormatJS extract which actually does support explicit IDs. So in theory we can use explicit IDs as well as automatic extraction. But the point of automatic extraction is to avoid manually specifying IDs. So the benefit of a hybrid approach is questionable.

I'm not sure what the best approach is, and I don't know how other large projects handle localization. If you can input your opinion, that would be great!

ysc3839 commented 3 years ago
  1. Hashes are not descriptive of the message content These hashes are not for translators, they are only for program. The translators see only original texts and translated texts.
  2. Hash changes when the original text changes Yes, but I don't think it's a problem. Translations is needed to maintain. If using ID, when the meaning of original text changed but translation remains unchanged, this may cause problem.
  3. Localization files should not be splitted This PR is still working in progress. This should be disscussed.

The main problem of using ID is you have to manually manage the ID -> text relations, which is easy to make errors and cost times.

There's many translate system. But macOS Cocoa, GNU gettext and Qt are using messages instead of ID. I don't know why they choose this, but I think they have their consideration.

ysc3839 commented 3 years ago

Added extract script to generate po file.

ysc3839 commented 3 years ago

Added generate script to generate json file from po file.

ysc3839 commented 3 years ago

I think this PR is done. When trnslating, use yarn extract to extract translatable strings to template file en-US.pot. Then you can use tools like Poedit to translate. After translate you get lang-code.po (For example: zh-CN.po), use yarn genlangs to generate lang-code.json.

ysc3839 commented 3 years ago

Also names of characters, artifacts... should be added to a file, in order to allow generate script add them to the template file.

ysc3839 commented 3 years ago

Fixed merge conflicts.

ysc3839 commented 3 years ago

@phosphene47 Yes. In such case you have to specific an ID manually.