Search the site
APP
Declare each string once as a typed key, and dartvel i18n tells you which languages are missing it.
Plurals follow the CLDR rules of each language.
ON THIS PAGE
Declare keys and load catalogues
Translate text and counts
Keep every language complete
Tell search engines about each language
Pick a language for a request
Status
class AppText {
static const DVTranslationKey cartTitle = DVTranslationKey('cart.title');
static const DVTranslationKey cartItems = DVTranslationKey('cart.items');
}
void loadTranslations() {
DV.I18n.loadAll(const <DVTranslationCatalog>[
DVTranslationCatalog(
locale: LocaleTag.enUS,
messages: <DVTranslationKey, String>{AppText.cartTitle: 'Your cart'},
plurals: <DVTranslationKey, DVPluralForms>{
AppText.cartItems: DVPluralForms(one: '{count} item', other: '{count} items'),
},
),
DVTranslationCatalog(
locale: LocaleTag.frFR,
messages: <DVTranslationKey, String>{AppText.cartTitle: 'Votre panier'},
plurals: <DVTranslationKey, DVPluralForms>{
AppText.cartItems: DVPluralForms(one: '{count} article', other: '{count} articles'),
},
),
]);
}Copy code to clipboard
A catalogue is const, with DVTranslationKey keys.
DVPluralForms takes zero, one, two, few, many and other, and the language decides which one a count uses.
DV.I18n.useLocale(LocaleTag.frFR);
final String title = DV.I18n.t(AppText.cartTitle); // Votre panier
final String count = DV.I18n.plural(AppText.cartItems, 3); // 3 articlesCopy code to clipboard
{name} placeholders are filled from args, and {count} from the count.
A missing key shows the key itself. Pass strict: true to throw instead.
DV.I18n.textDirection is rtl for Arabic, Hebrew, Persian and the other right-to-left languages.
dartvel i18n extract --locale en --locale fr
dartvel i18n check --strictCopy code to clipboard
extract finds every DVTranslationKey under lib/ and writes lib/l10n/app_<locale>.arb, keeping translations you have.
check lists untranslated and no-longer-used keys per language. --strict fails, for CI.
# pubspec.yaml
dartvel:
seo:
siteUrl: https://example.com
i18n:
locales: [en, fr]
defaultLocale: enCopy code to clipboard
With two or more locales, dartvel build web writes hreflang links on every page: /about for the default and /fr/about for French, plus x-default.
dvNegotiateLocale from dartvel_core chooses among your supported locales. A /fr/ path wins, then a stored preference, then Accept-Language, then the tenant's default, then your fallback.
Built
Spec section: Internationalization and Localization
FSL-1.1-MIT licensed. Built with Dartvel.
Dartvel is made by
To the bottom