diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-03-13 15:17:03 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-03-13 15:17:03 +0000 |
| commit | d37db671e2f4b9f27d817b54a435ecf154a67a6b (patch) | |
| tree | 475cd8dda9bb64eaf9b2e8d32c1464233356402a /app/I18N.php | |
| parent | b0c01d0c28a4ee291803e9f36bcb20e3f916c3da (diff) | |
| download | webtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.tar.gz webtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.tar.bz2 webtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.zip | |
Allow custom modules to provide translations
Diffstat (limited to 'app/I18N.php')
| -rw-r--r-- | app/I18N.php | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/I18N.php b/app/I18N.php index 1fafb0b79b..b86804474b 100644 --- a/app/I18N.php +++ b/app/I18N.php @@ -26,6 +26,8 @@ use Fisharebest\Localization\Locale\LocaleInterface; use Fisharebest\Localization\Translation; use Fisharebest\Localization\Translator; use Fisharebest\Webtrees\Functions\FunctionsEdit; +use Fisharebest\Webtrees\Module\ModuleCustomInterface; +use Fisharebest\Webtrees\Services\ModuleService; use const GLOB_NOSORT; /** @@ -33,6 +35,10 @@ use const GLOB_NOSORT; */ class I18N { + // MO files use special characters for plurals and context. + public const PLURAL = '\x00'; + public const CONTEXT = '\x04'; + /** @var LocaleInterface The current locale (e.g. LocaleEnGb) */ private static $locale; @@ -376,10 +382,11 @@ class I18N * * @param string $code Use this locale/language code, or choose one automatically * @param Tree|null $tree + * @param bool $custom Load custom translations * * @return string $string */ - public static function init(string $code = '', Tree $tree = null): string + public static function init(string $code = '', Tree $tree = null, $custom = true): string { if ($code !== '') { // Create the specified locale @@ -438,6 +445,16 @@ class I18N $translations = include $cache_file; } + // Add translations from custom modules (but not during setup) + if ($custom) { + $custom_modules = app(ModuleService::class)->findByInterface(ModuleCustomInterface::class); + + foreach ($custom_modules as $custom_module) { + $custom_translations = $custom_module->customTranslations(self::$locale->languageTag()); + $translations = array_merge($translations, $custom_translations); + } + } + // Create a translator self::$translator = new Translator($translations, self::$locale->pluralRule()); |
