3

I am having some issues setting up translation functions for localization in my Dart application. I currently have 1 class called basics.dart, and all classes have access to its functions. Here is the function that I want translated:

basics.dart

String loadingMessage() {
  return  Intl.message(
    "Tickets are currently loading",
    name: "loadingMessage",
    args: [],
    desc: "Tickets are currently loading");
}

ticket_list.dart

  _p.text = loadingMessage();//'Currently loading the tickets';

This returns the message in English correctly. Now how do I set it up so I can get French translations as well?

1 Answers1

2

See the doc of the intl package.

Basically you need to extract the messages to translate with :

pub run intl:extract_to_arb --output-dir=target/directory
  my_program.dart more_of_my_program.dart

Then translate the arb files and finally generate .dart file for translated messages with :

 pub run intl:generate_from_arb --generated_file_prefix=<prefix> 
  <my_dart_files> <translated_ARB_files>
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
  • Thanks! I was able to generate the .arb file with my message in it, however what am I supposed to put for the in the second command? And how will it know I want my translations to be for the French locale? – gamefreak249 Oct 31 '14 at 15:04
  • Once you have translate the `content.arb` and create `content_fr.arb`, `content_en.arb` ... Then if you use `--generated-file-prefix=content_` the script will generate `content_messages_all.dart`, `content_messages_fr.dart` and `content_messages_en.dart`. – Alexandre Ardhuin Oct 31 '14 at 15:20
  • That worked great, and that generated content_messages_fr.dart. However, my program still calls the English function. Are these .dart files supposed to go anywhere specific? They are currently in the root of my projects folder. – gamefreak249 Oct 31 '14 at 15:52
  • You have to import `content_messages_all.dart` and call `initializeMessages('fr')` – Alexandre Ardhuin Oct 31 '14 at 16:32
  • And note that it returns a future, so the translated message aren't available until it completes – Alan Knight Nov 01 '14 at 19:48