Internationalization add-on along with .mo files

Permalink
Hi guys,

I have a multi languages website which works great with the add-on.
I have developed a package which is translated and should display the t() strings in the language chosen by the user.

The issue is that, as far as I know Concrete5, to use the .mo files of my package, I have to set LOCALE in my site.php, which is not the right solution as the user is supposed to be able to switch the language by himself.

Having some logic in config/site.php is possible but not dynamic as it is not yet possible to access the Database. And it would require to parse the URL by hand which is a shame as the Core would do that a few includes later.

As for now I guess I could sort it out by hardcoding values in the config file, but I'd really like my client to be able to add/delete languages on the fly and having the translations displayed.

Did anyone of you come up with a solution to use the add-on (or how to use the add-on) to load the current language .mo files?

Thanks a lot for your feedbacks.

Fred

 
Mainio replied on at Permalink Reply
Mainio
1. Remove the LOCALE definition from your site.php
2. Go to your /languages directory and create a folder called "site"

Now the internationalization add-on should catch up automatically all your package translations for the site as well.

Yes, it is a funky/buggy behavior in the internationalization add-on but it should work after all.
FMC replied on at Permalink Reply
Thank you, but, unfortunately it does not work. I guess that's because ACTIVE_LOCALE is used to set the locale for the packages and if the user is not logged in which is the case for my visitors the language is set from the constants and not the add-on.

I also realised that setting the constant in site.php is tricky because of URL parsing, and even impossible when the page is referenced by cID. Using site_post.php does not help as thr constants are already set.

Any other idea?
Mainio replied on at Permalink Reply
Mainio
Yes, I don't think the above affects setting of the locale constant but it should load the translation files for every package and site translations according to the language section you're browsing.

If you want to hack it, there is a function in the localization class:
Localization::changeLocale('xx_XX');
FMC replied on at Permalink Reply
I see, the problem is that the translate variable in Localization is not set because I don't have any other translation on a site level. I will have to fake it in order for this to work. I'll give it a shot tonight and update this post.

Thank you!
FMC replied on at Permalink Best Answer Reply
I finally got it working. Here are the steps I had to follow:

- Use poedit to extract strings from Concrete Core
- Create a new translation of the core using poedit and placing it in /languages/fr_FR/message.po (I haven't translated anything)
- Copied my package translation to /languages/site/fr_FR.po (some versions of Concrete require the file to be fr.po)

And there it works.

But, this is definitely not the ultimate solution. As the locale is not set properly, the language file in /languages/fr_FR and /packages/myPackage/languages/fr_FR/ won't be used. Which is bad...

Thank you for your help!
onemhz replied on at Permalink Reply 1 Attachment
onemhz
Yes, strange, I have same problem BUT only for C5 version 5.5.x, translation in version 5.4.x for add-ons and site works very well.

In both version same way, same folders, and strange strings in 5.5x disapear when I delete language folder for add-on.

I wish to do not add add-on translation to .po when early worked well
and have one for site one for add-on.

(see screen)