Jefferson49 / ChangeLanguageWithURL

A weebtrees custom module to change the webtrees language by URL requests with the language provided as an URL parameter.
GNU General Public License v3.0
0 stars 0 forks source link

error when using language "en" #2

Closed hartenthaler closed 2 years ago

hartenthaler commented 2 years ago

Your module is working for "de" or "cs" (using .../index.php?route=%2Ftree%2Ftree3&language=de). But it is not working for "en":

file(…/app/../resources/lang/en/messages.po): Failed to open stream: No such file or directory …/vendor/fisharebest/localization/src/Translation.php:56
#0 [internal function]: Fisharebest\Webtrees\Webtrees::Fisharebest\Webtrees\{closure}()
#1 …/vendor/fisharebest/localization/src/Translation.php(56): file()
#2 …/app/I18N.php(310): Fisharebest\Localization\Translation->__construct()
#3 …/modules_v4/change_language_with_url/ChangeLanguageWithURL.php(109): Fisharebest\Webtrees\I18N::init()

And it is not working for "xxxx".

xxxx …/vendor/fisharebest/localization/src/Locale.php:62
#0 …/app/I18N.php(297): Fisharebest\Localization\Locale::create()
#1 …/modules_v4/change_language_with_url/ChangeLanguageWithURL.php(109): Fisharebest\Webtrees\I18N::init()
#2 …/vendor/oscarotero/middleland/src/Dispatcher.php(136): ChangeLanguageWithURLNamespace\ChangeLanguageWithURL->process()
#3 …/modules_v4/webtrees-reminder/src/Modules/ReminderModule.php(97): Middleland\Dispatcher->handle()

I don't know if this has to be fixed in your module or in the webtrees core.

Jefferson49 commented 2 years ago

Thank you for testing the module.

For English, the language codes are "en-AU", "en-GB", and "en-US".

However, I agree that the module should be more defensive and should not react with an error message in case of &language=xxx. Currently, the only check is that the language is not empty. I will search for a possibility to test for existing locales.

Arguably, webtrees should also test for an existing language. The related code to set the language is:

Session::put('language', $language);

If I do not find an easy solution in my module code, I will raise a ticket in webtrees.

hartenthaler commented 2 years ago

Good idea! I see it the same way.

Jefferson49 commented 2 years ago

Robustness measures added to the code in order to check for appropriate language tag. If a wrong language tag is provided, an error message is shown.