magicbug / Cloudlog

Web based amateur radio logging application built using PHP & MySQL supports general station logging tasks from HF to Microwave with supporting applications to support CAT control.
http://www.cloudlog.co.uk
MIT License
439 stars 188 forks source link

Possible problem with translations and selected default language #880

Closed dgdavid closed 3 years ago

dgdavid commented 3 years ago

:warning: DISCLAIMER: maybe what I'm going to report is completely wrong, but I strongly believe it worth having a look at it :warning:

Context

Last weekend, @leroydiazg pinged me because he noticed that something weird was happening with the Spanish translations in the instance we have set up. That instance has the 'spanish' language set as default in the config file (application/config/config.php).

Leroy told me that "Notes" translations were not working as expected despite the 'application/languages/spanish/notes_lang.php' was there while the rest of the translations were being shown. Mysterious enough.

The problem (?)

So, after looking here and there to check everything was fine, we ended doing a rudimentary debugging[1] of the system/core/Lang.php file, using the PHP print command inside the load method :man_facepalming: to see which idiom was being used per each langfile. The result was something like

general_words_lang.php => 'spanish'
migration_lang.php => 'spanish'
notes_lang.php => 'english'

That pointed us out to the migration files and... there seems to be half of the problem[2]:

https://github.com/magicbug/Cloudlog/blob/4ca443de3f831d3e833fb7a5cd3b41c71252a80a/application/migrations/061_add_lang_to_options.php#L15

As far as we can see, support for setting the language preference in the database has been added recently, setting it to 'english' by default.

So, looks like autoloaded lang files ('general_words' at this moment) are being loaded using the default language set in the config file and the rest using the preferred language set by the DB.

Proposed solutions (or just crazy ideas)

Assuming that I'm right (which could be not), I'd propose

Or (even better?) to wrap $this->lang->load in a custom helper to set the preferred or default language as the second param when it is not given.


[1] Probably looking at server logs would have been a better idea, but that's another story. [2] The other half is in the OptionsLib - https://github.com/magicbug/Cloudlog/commit/4770340c45321f7c1d081e9c61b052210076194a

magicbug commented 3 years ago

What I did do was write some frontend code that added language selection inside global options it's then grabbed and set with all the other options data.

Ultimately this should overide the. Config.php selection and you'd need to reselect within the frontend but I didn't expect that to cause any problems

dgdavid commented 3 years ago

but I didn't expect that to cause any problems

It does, I just checked it right now by setting the instance in the other way around: 'english' in the config file, 'spanish' in the database. As said, general_words lang file (the one autoloaded) is honoring the configuration set in the config.php file. Yo can do a simple test by yourself or maybe one of the other guys involved in other translations can do it and confirm or deny the issue.

dgdavid commented 3 years ago

@ok1cdj, @oh1jw, @phl0, friendly ping :point_up: :point_up:

magicbug commented 3 years ago

OK so there does appear to be an issue with languages which don't have appropriate code lang files present in Codeigniter like Finnish you get errors like

Unable to load the requested language file: language/finnish/pagination_lang.php

It makes me think that these files need to be included else nothing works

Looking at the QSO Panel for each

this was with changing languages within global options and the config.php set to $config['language'] = 'english';

So I'm confused by what the problem is although bit drugged up on meds, German I thought was OK although doesn't seem to be so I'll fall back to @phl0 to have a look, Finnish it seems we need a core set of lang files to handle things correctly.

thus I'll wait to see what the others say, as I'm not quite grasping the issue.

magicbug commented 3 years ago

If you want to test what I changed you can comment out $CI->config->set_item($item->option_name, $item->option_value); from libraries/OptionsLib.php on line 36.

magicbug commented 3 years ago

OK so Unable to load the requested language file: language/dutch/notes_lang.php doesn't load if its missing and removing the code changes I made makes zero change once a views been converted there's no fallback to english

dgdavid commented 3 years ago

OK so there does appear to be an issue with languages which don't have appropriate code lang files present in Codeigniter like Finnish you get errors like

Unable to load the requested language file: language/finnish/pagination_lang.php

It makes me think that these files need to be included else nothing works

Looking at the QSO Panel for each

* Czech seems complete

* Dutch - seems complete

* English - fine

* finnish - get errors as above

* french - loads ok

* German for example if i go to QSO I get lots of missing fields

* Spanish loads OK

this was with changing languages within global options and the config.php set to $config['language'] = 'english';

Go to notes instead. Most probably you'll see nothing translated.

So I'm confused by what the problem is although bit drugged up on meds, German I thought was OK although doesn't seem to be so I'll fall back to @phl0 to have a look, Finnish it seems we need a core set of lang files to handle things correctly.

thus I'll wait to see what the others say, as I'm not quite grasping the issue.

Sorry if I was not able to express the issue clearly. I tried it, believe me.

dgdavid commented 3 years ago

If you want to test what I changed you can comment out $CI->config->set_item($item->option_name, $item->option_value); from libraries/OptionsLib.php on line 36.

In fact, here is where I think the problem starts. Commenting the line, the language set in the config file is always honored. When not, the translations declared in the general_words_lang are being translated to the language set in the config file and the rest (or at least those in notes_lang) use the language set by this line.

At least in my tests.

magicbug commented 3 years ago

Just to quickly resolve this till I get more hours in the day, I've removed the option and hidden the feature in global settings for now config manual change will be the only option.

oh1jw commented 3 years ago

I noticed that there was completely missing finnish translation at Codeigniter. I just translated it and made PR. It might solve the problem.

dgdavid commented 3 years ago

I noticed that there was completely missing finnish translation at Codeigniter. I just translated it and made PR.

Great! Don't forget to add them here too, maybe once your PR get merged.

It might solve the problem.

Actually not. Well, let's say partially. I mean, the problem spotted here is different that the one I already mentioned in #799 related to the "empty" string when translation is missing, which most probably is what you noticed.

Anyway, Peter already undid the changes related with this issue.

oh1jw commented 3 years ago

I noticed that there was completely missing finnish translation at Codeigniter. I just translated it and made PR.

Great! Don't forget to add them here too, maybe once your PR get merged.

Sorry, I'm a newbie with Github - is there any easy way to duplicate them after they are merged?

dgdavid commented 3 years ago

Sorry, I'm a newbie with Github

No problem, welcome :)

  • is there any easy way to duplicate them after they are merged?

I don't think so[1]. Just follow the https://github.com/bcit-ci/codeigniter3-translations instructions and

Copy the folder(s) for the idioms you are interested in, from inside the language folder of this project to your application/language folder.

and made a PR against Cloudlog


[1] although the project could use a Github action or other process/technique to automatize the task of fetching the most recent translations for languages at application/languages from https://github.com/bcit-ci/codeigniter3-translations in, let's say, each release. But definitely this is nothing you can do and it is not "the easy way" you were asking for :)

dgdavid commented 1 year ago

JFTR, fixed by @AndreasK79 in https://github.com/magicbug/Cloudlog/pull/2138