Pakete, Repositories und App-Kategorien suchen

GitHub-Repositoryerf/toml_localizations

toml_localizations

TOML-Lokalisierung für Flutter

Projektcover von toml_localizations
Sterne
2
Forks
0
Letzter Push (UTC)
07.07.2025
Projektstatus
Aktiv

Original-README

Englischer Projektschnappschuss. Aktuelle Inhalte auf GitHub.

toml_localizations

A minimal TOML localization package for Flutter.

TOML is a minimal, easy to read, configuration file format, which allows you to represent strings (and other types) as key/value pairs.

Install

Add toml_localizations and flutter_localizations as dependencies to your pubspec.yaml.

dependencies:
  flutter_localizations:
    sdk: flutter
  toml_localizations: <last-version>
Add assets

Add a TOML file per language to a asset path and define it in your pubspec.yaml.

flutter:
  assets:
    - assets/toml_translations

The TOML file name must match exactly the combination of language and country code described in supportedLocales.

That is Locale('en', 'US') must have a corresponding assetPath/en-US.toml file.

Add localization delegate and supported locales

Add TomlLocalizationsDelegate to MaterialApp and set supportedLocales to supported language/country codes.

MaterialApp(
  localizationsDelegates: [
    // delegate from flutter_localization
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    // toml localizations delegate
    TomlLocalizationsDelegate(path: 'assets/toml_translations')
  ],
  supportedLocales: [
    Locale('en', 'GB'),
    Locale('en', 'US'),
    Locale('en'),
    Locale('nb'),
  ],
}
Note on iOS

Add supported languages to ios/Runner/Info.plist as described here.

Example:

<key>CFBundleLocalizations</key>
<array>
	<string>en</string>
	<string>en-GB</string>
	<string>en-US</string>
	<string>nb</string>
</array>

Format

Example TOML file:

str = "The quick brown fox jumps over the lazy dog."

literal_str = 'C:\Users\nodejs\templates'

multiline_str = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""

literal_multiline_str = '''
The first newline is
trimmed in raw strings.
   All other whitespace
   is preserved.
'''

list = [ 'one', 'two', 'three' ]

Tip: Toml supports several ways of expressing strings. See Toml documentation for more info.

API

Translate strings or other types using:

TomlLocalizations.of(context)!.value(this);

We keep the API simple, but you can easily add an extension method to String like this:

extension LocalizedString on String {
  String tr(BuildContext context) => TomlLocalizations.of(context)!.value(this);
}

Se you could translate strings like this:

'Hi'.tr(context)

Example

See example

Erlend GitHub avatar
GitHub-Autor

Erlend ↗

SprachenDartPythonSwiftKotlinObjective-C

Kategorien

Von diesem Repository veröffentlichte Pakete

Verwendete Abhängigkeiten

Abhängigkeiten 5 Einträge

  • flutter{"sdk":"flutter"}
  • toml^0.16.0
  • flutter_testEntwicklung{"sdk":"flutter"}
  • flutter_localizationsEntwicklung{"sdk":"flutter"}
  • flutter_lintsEntwicklung^6.0.0

Wie wähle ich ein passendes Repository?

Nach Anwendungsfall filtern, Aktivität vergleichen und vor der Nutzung das Originalprojekt prüfen.

  1. Nach Name, Autor oder Beschreibung suchen und nach Thema eingrenzen.
  2. Sterne, Forks und letzte Pushes vergleichen. Sterne zeigen Interesse, garantieren aber keine Qualität.
  3. Vor der Nutzung README, Lizenz und Issues auf GitHub prüfen.

Quellen und Pflege

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗