Skip to content

Commit

Permalink
feat: Migrate to Mineral Law release
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev committed Dec 11, 2022
1 parent b3875f4 commit c46631f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/mineral_i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ library i18n;

export 'src/i18n.dart';
export 'src/lang.dart';
export 'src/contracts/i18n_contract.dart';
export 'src/mixins/translation.dart';

22 changes: 15 additions & 7 deletions test/mineral_i18n_test.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import 'package:mineral_i18n/mineral_i18n.dart';
import 'package:mineral_i18n/src/mixins/translation.dart';
import 'package:mineral_ioc/ioc.dart';
import 'package:test/test.dart';

class Foo with Translation {
Function get translator => t;
}

void main() {
final foo = Foo();
final String targetTranslation = 'foo.bar';
final i18n = I18n([Lang.fr, Lang.enGB])
..registerLanguages();

i18n.translation
i18n.translationManager
..addTranslations(Lang.fr, { targetTranslation: 'Salut {user}' })
..addTranslations(Lang.enGB, { targetTranslation: 'Hello {user}' });

test('can register i18n into mineral ioc', () {
ioc.bind(namespace: I18n.namespace, service: i18n);
expect(ioc.singleton(I18n.namespace), equals(i18n));
final dynamic pluginManager = ioc.services.entries.firstWhere((element) => element.key.toString() == 'PluginManagerCraft').value;
pluginManager.bind((ioc) => I18n([Lang.fr, Lang.enGB]));

expect(pluginManager.use(), equals(i18n));
});

test('registered lang is two', () {
Expand All @@ -22,12 +30,12 @@ void main() {
});

test('can translate sentence without variables', () {
expect(t(Lang.fr, targetTranslation), equals('Salut {user}'));
expect(t(Lang.enGB, targetTranslation), equals('Hello {user}'));
expect(foo.translator(Lang.fr, targetTranslation), equals('Salut {user}'));
expect(foo.translator(Lang.enGB, targetTranslation), equals('Hello {user}'));
});

test('can translate sentence with variables', () {
expect(t(Lang.fr, targetTranslation, replacers: { 'user': 'Freeze' }), equals('Salut Freeze'));
expect(t(Lang.enGB, targetTranslation, replacers: { 'user': 'Freeze' }), equals('Hello Freeze'));
expect(foo.translator(Lang.fr, targetTranslation, replacers: { 'user': 'Freeze' }), equals('Salut Freeze'));
expect(foo.translator(Lang.enGB, targetTranslation, replacers: { 'user': 'Freeze' }), equals('Hello Freeze'));
});
}

0 comments on commit c46631f

Please sign in to comment.