diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-03-14 20:48:52 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-03-14 20:48:52 +0000 |
| commit | c116a5cceea9f41568eb8b09121d6846ba0546e7 (patch) | |
| tree | 58fe49d69c6f6b3eabd83b7f28d77c16a55f80c2 /app/I18N.php | |
| parent | 93b73e0f9a6630fd308a14cc9db1a68b1fb476a1 (diff) | |
| download | webtrees-c116a5cceea9f41568eb8b09121d6846ba0546e7.tar.gz webtrees-c116a5cceea9f41568eb8b09121d6846ba0546e7.tar.bz2 webtrees-c116a5cceea9f41568eb8b09121d6846ba0546e7.zip | |
Catch 22 - setup needs language modules. Modules need a database. Database needs setup
Diffstat (limited to 'app/I18N.php')
| -rw-r--r-- | app/I18N.php | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/app/I18N.php b/app/I18N.php index c2ca0d425a..4e6e0f9799 100644 --- a/app/I18N.php +++ b/app/I18N.php @@ -332,13 +332,13 @@ class I18N /** * Initialise the translation adapter with a locale setting. * - * @param string $code Use this locale/language code, or choose one automatically + * @param string $code Use this locale/language code, or choose one automatically * @param Tree|null $tree - * @param bool $custom Load custom translations + * @param bool $setup During setup, we cannot access the database. * * @return string $string */ - public static function init(string $code = '', Tree $tree = null, $custom = true): string + public static function init(string $code = '', Tree $tree = null, $setup = true): string { if ($code !== '') { // Create the specified locale @@ -355,7 +355,16 @@ class I18N // Negotiate with the browser. // Search engines don't negotiate. They get the default locale of the tree. - self::$locale = Locale::httpAcceptLanguage($_SERVER, self::installedLocales(), $default_locale); + if ($setup) { + $installed_locales = app(ModuleService::class)->setupLanguages() + ->map(function (ModuleLanguageInterface $module): LocaleInterface { + return $module->locale(); + }); + } else { + $installed_locales = self::installedLocales(); + } + + self::$locale = Locale::httpAcceptLanguage($_SERVER, $installed_locales->all(), $default_locale); } $cache_dir = WT_DATA_DIR . 'cache/'; @@ -398,7 +407,7 @@ class I18N } // Add translations from custom modules (but not during setup) - if ($custom) { + if (!$setup) { $custom_modules = app(ModuleService::class) ->findByInterface(ModuleCustomInterface::class); @@ -433,16 +442,16 @@ class I18N /** * All locales for which a translation file exists. * + * @return Collection * @return LocaleInterface[] */ - public static function installedLocales(): array + public static function installedLocales(): Collection { return app(ModuleService::class) ->findByInterface(ModuleLanguageInterface::class, true) ->map(function (ModuleLanguageInterface $module): LocaleInterface { return $module->locale(); - }) - ->all(); + }); } /** |
