-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mineral-dart/feat-migrate-package-to-miner…
…al-2 Feat migrate package to mineral 2
- Loading branch information
Showing
9 changed files
with
128 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:mineral_i18n/src/lang.dart'; | ||
|
||
abstract class I18nContract { | ||
List<Lang> get languages; | ||
Directory get langPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:mineral_i18n/mineral_i18n.dart'; | ||
import 'package:mineral_ioc/ioc.dart'; | ||
|
||
mixin Translation { | ||
I18n _getPlugin () { | ||
final dynamic pluginManager = ioc.services.entries.firstWhere((element) => element.key.toString() == 'PluginManagerCraft').value; | ||
return pluginManager.use<I18n>(); | ||
} | ||
|
||
/// Translates the sentence defined by the key set into the requested language. | ||
/// Replacement parameters can be injected. | ||
/// ```dart | ||
/// final String sentence = t(Lang.enGB, 'foo.bar'); | ||
/// print(sentence) 👈 'Hello {user}' | ||
/// | ||
/// final String sentence = t(Lang.enGB, 'foo.bar', { 'user': 'Freeze' }); | ||
/// print(sentence) 👈 'Hello Freeze' | ||
/// ``` | ||
String t (Lang lang, String key, { Map<String, dynamic>? replacers }) { | ||
dynamic target = _getPlugin().translationManager.cache[lang.normalize]; | ||
for (final element in key.split('.')) { | ||
target = target[element]; | ||
} | ||
|
||
if (replacers != null) { | ||
for (final replacer in replacers.entries) { | ||
target = target.toString().replaceAll('{${replacer.key}}', replacer.value); | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.