This provides utilities for generating localized versions of messages. It does not stand alone, but expects to be given TranslatedMessage objects and generate code for a particular locale based on them.

An example of usage can be found in test/message_extract/generate_from_json.dart

Constants

closing → dynamic

Constant string used in generateMainImportfile as the end of the file.

""" default: return null; } } /** User programs should call this before using [localeName] for messages.*/ initializeMessages(localeName) { initializeInternalMessageLookup(() => new CompositeMessageLookup()); messageLookup.addLocale(localeName, _findGeneratedMessagesFor); return new Future.value(); } MessageLookupByLibrary _findGeneratedMessagesFor(locale) { var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); if (actualLocale == null) return null; return _findExact(actualLocale); } """

Properties

allLocales → List<String>

A list of all the locales for which we have translations. Code that does the reading of translations should add to this.

read / write
generatedImportPath → dynamic

If the path to the generated files is something other than the current directory, update the generatedImportPath variable to change the import directives in the generated code.

read / write
intlImportPath → dynamic

If the import path following package: is something else, modify the intlImportPath variable to change the import directives in the generated code.

read / write
mainPrologue → dynamic

Constant string used in generateMainImportFile for the beginning of the file.

read / write

Functions

asLibraryName(String x) → String

We can't use a hyphen in a Dart library name, so convert the locale separator to an underscore.

generateIndividualMessageFile(String locale, Iterable<TranslatedMessage> translations, String targetDir) → void

Generate a file messages_<locale>.dart for the translations in locale.

generateMainImportFile() → String

This section generates the messages_all.dart file based on the list of allLocales.

importForGeneratedFile(String file) → String

Given a base file, return the file prefixed with the path to import it. By default, that is in the current directory, but if generatedImportPath has been set, then use that as a prefix.

prologue(String locale) → String

This returns the mostly constant string used in generated for the beginning of the file, parameterized by locale.

Classes

TranslatedMessage

This represents a message and its translation. We assume that the translation has some identifier that allows us to figure out the original message it corresponds to, and that it may want to transform the translated text in some way, e.g. to turn whatever format the translation uses for variables into a Dart string interpolation. Specific translation mechanisms are expected to subclass this.