dart-lang / i18n

A general mono-repo for Dart i18n and l10n packages.
BSD 3-Clause "New" or "Revised" License
64 stars 40 forks source link

[question] Translate string without name #654

Open fawdlstty opened 1 year ago

fawdlstty commented 1 year ago

I have implemented some multilingual support requirements through l18n, but there is a new requirement to obtain English strings from the network and convert them to other language strings. I have ensured that the localization file contains the english strings, but I am unable to obtain the name of the original string. However, calling Intl.message requires that the 'name' must be passed in. How should I obtain name based on the original text of the string to achieve direct translation?

mosuem commented 1 year ago

I don't completely understand. So you have an .arb file containing English strings, or are you receiving them over the network?

On-the-fly switching is not supported by package:intl_translation, as the arb files are used to generate code which has to be compiled into the final application.

fawdlstty commented 1 year ago

I receive the original English text over the network and store it in a string. And I am sure that the original text corresponds to the content in the arb file one by one. I want to translate the English original text through arb

mosuem commented 1 year ago

I am sorry, I still don't understand - if the strings you receive are also in an arb file, and you have the other translations also stored as arb files, then why not retrieve the name by looking it up in file?

fawdlstty commented 1 year ago

I don't know how to retrieve the contents of the arb file in the program. In my opinion, the arb file is used to generate the l10n.dart file and then call the methods in the l10n.dart file to implement the translation. If you want to retrieve the arb file in the application, you need to add the arb file to assets. In my opinion, since the program already generates the corresponding code through the arb file, it should be translated through the corresponding code, rather than adding the arb file into assets