mineral_i18n 2.0.0 copy "mineral_i18n: ^2.0.0" to clipboard
mineral_i18n: ^2.0.0 copied to clipboard

I18n allows you to translate your text content into multiple languages

🌐 I18n #

The i18n module has been designed exclusively for the Mineral framework, it allows you to translate your textual content through yaml files.

Register the module #

After installing the module, please register it within ./src/main.dart following the scheme below :

Future<void> main () async {
  final i18n = I18n([Lang.fr, Lang.enGB]);
  
  Kernel kernel = Kernel()
    ..intents.defined(all: true)
    ..plugins.use([i18n]);
  
  await kernel.init();
}

Translate your textual content #

As a first step, please create a lang folder containing {lang}.yaml translation files.

We consider the following software structure :

lang/
  foo/
    fr.yaml
    en.yaml

The files will contain the following keys :

# lang/foo/fr.yaml
bar: bar en français !
# lang/foo/en.yaml
bar: bar in english !

Then we can use the t() function to translate our key path.

import 'package:mineral_i18n/mineral_i18n.dart';

class Foo extends MineralEvent<Ready> with Translation {
  Future<void> handle (Ready event) async {
    final String sentence = t(Lang.fr, 'foo.bar');
    print(sentence); // bar en français !

    final String sentence = t(Lang.en_GB, 'foo.bar');
    print(sentence); // bar in english !
  }
}

Injecting variables #

The i18n module integrates the possibility of using variables thanks to special characters which will be replaced by the associated variable.

We consider the file lang/foo/en.yaml as containing the following key set :

bar: {framework} is my favourite framework ! 

Our string is now waiting for a variable named xx which we will give it when we call the t() function.

import 'package:mineral_i18n/mineral_i18n.dart';

class Foo extends MineralEvent<Ready> with Translation {
  Future<void> handle (Ready event) async {
    final String sentence = t(Lang.en_GB, 'foo.bar', { 'framework': 'Mineral' });
    print(sentence); // Mineral is my favourite framework ! 
  }
}
0
likes
140
pub points
0%
popularity

Publisher

verified publishermineral-foundation.org

I18n allows you to translate your text content into multiple languages

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

mineral, mineral_contract, mineral_ioc, path, yaml

More

Packages that depend on mineral_i18n