8.4.3 Interface translation doesn't work

Permalink
I have 2 locales: the main and default one is Russian and the other one is English. User enters text in English in a package. I need it to be translated to Russian for the default locale. It will remain in English for the English locale anyway.

I've set up the multilingual settings. And I have this code in the package controller:
public function getTranslatableStrings(\Gettext\Translations $translations)
{
    $db = $this->app->make('database')->connection();
    $rs = $db->executeQuery('select category from MY_PACKAGE_DB');
    while (($category = $rs->fetchColumn()) !== false) {
        $translations->insert('', $category);
    }
    $this->app->make('config')->save('concrete.misc.enable_translate_locale_base_locale', true);
}

I have searched for the strings which have to be translated and saved their translations. Then I've saved the translations file.

I've cleared cache, I've refreshed the page but nothing gets translated. All words I saved translation for are unchanged.

Is that going to work at all? Or should I enter text in Russian for the default locale and then rather translate it to English for the other locale?

I've also tried entering text in Russian, then I refreshed the strings in Multilingual setup, translated all Russian strings into English, saved file, went to English locale, added the same block, cleared cache, refreshed page - no change, all Russian text is still in Russian, doesn't get translated.

What can be wrong? Anyone has ever successfully translated the interface from some language to English?

And how can I have all global area text translated?

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
Anyone?
mlocati replied on at Permalink Reply
mlocati
Why did you add this code?

$this->app->make('config')->save('concrete.misc.enable_translate_locale_base_locale', true);


You also posted another question: " And how can I have all global area text translated?"
Stacks and global areas can have a multilingual version (edit a global area in the /dashboard/blocks/stacks dashboard page)
linuxoid replied on at Permalink Reply
linuxoid
Michele,
Because you told me to ))

https://www.concrete5.org/community/forums/internationalization/8.4....

The thing is I tried both options:
1. text strings in package entered in Russian, everything's fine with RU locale, all these Russian words are found in the interface translation, I added English translations for all of them, cleared cache and all, I go to EN locale - and nothing is translated
2. text strings in package entered in English, everything's fine with EN locale, all these English words are found in the interface translation, I added Russian translations for all of them, cleared cache and all, I go to RU locale - and nothing is translated

Nothing gets translated for user entered text. What am I doing wrong? They are founf by the search, translations added, but don't get translated.
linuxoid replied on at Permalink Reply
linuxoid
Has anyone successfully set up a multilingual site with user text translation?

I can't get it to work. A Howto or Tutorial would be really good.
linuxoid replied on at Permalink Reply
linuxoid
P l e a s e h e l p, s o m e o n e!!!
mlocati replied on at Permalink Reply
mlocati
I think I tried to help you as much as possible, without a full copy of your website.
If I were you I'd use xdebug to see what's going wrong.
With xdebug you can see exactly what's happening (here's a sample session:http://youtu.be/iyki8lzzwms )
linuxoid replied on at Permalink Reply
linuxoid
Michele,
I'd rather like to know how exactly a multilingual site has to be set up for user text to be translated. I can't find it anywhere. Does the main locale have to be English, text in English and then translated? What needs to be done if the main locale is not English?
mlocati replied on at Permalink Reply
mlocati
I've always used English as the main language. I don't know if concrete5 supports another language as main one.
linuxoid replied on at Permalink Reply
linuxoid
Ok. I made US a default locale. Added a new Russian locale. Copied the tree. Translated English user words in the Translate Site Interface, saved the file, went to the Russian site page - nothing is translated.

I've checked the application/languages/site/ru_RU.po - the text is translated there.

Are these steps correct? Obviously something's missing.

I really want to hear if anyone has actually been successful in setting up user text translation on a multilingual site.
mlocati replied on at Permalink Reply
mlocati
You can check that you have the expected language, by adding this code right after the t()/tc()/t2() calls:

<?= '<p>Current language: ', \Localization::activeLocale(), '</p>' ?>
linuxoid replied on at Permalink Reply
linuxoid
Yes, the language is correct. AND all other strings DO get translated EXCEPT for those entered by the user!
mlocati replied on at Permalink Reply
mlocati
First, remove the line

$this->app->make('config')->save('concrete.misc.enable_translate_locale_base_locale', true);


from the getTranslatableStrings method of your package controller (you have to configure concrete5 just once, not every time you export the translations).

Then, follow these steps:

1. go to the /dashboard/system/multilingual/translate_interface dashboard page and click the "Reload strings" button

2. be sure that the strings you want to be translated are in the language files.
For example, if your getTranslatableStrings method adds the English string "Test" to the translations, and if you have a Russian (ru_RU) language section in your website, you should have a file named application/languages/site/ru_RU.po and it should contain these lines:

msgid "Test"
msgstr ""


3. in the /dashboard/system/multilingual/translate_interface dashboard page, translate the missing strings (click the Pen icon on the right of Russian row).

4. Back to the /dashboard/system/multilingual/translate_interface page, hit the "Save to file" button

5. Check that concrete5 saved the translations to file.
With the example data above (an English string "Test" and Russian), you should have these lines in the application/languages/site/ru_RU.po file:

msgid "Test"
msgstr "the Russian translation of Test"


6. Now, every time you call t("Test") and the current language is Russian, concrete5 should print out the Russian translation of "Test"
linuxoid replied on at Permalink Reply 5 Attachments
linuxoid
That's exactly what I've done - nothing (no user text) gets translated. Please see the attached pics.

I've also tried what's said at the bottom of this page:
https://documentation.concrete5.org/developers/interface-customizati...

that is I made a ru.php in /application/src:
<?php
defined('C5_EXECUTE') or die('Access Denied.');
return;
t('Economy');

I've reloaded the strings, added translation for that string, saved file, checked it - it's there, reloaded the page - NOT translated!
mlocati replied on at Permalink Reply
mlocati
If you add
<?= '<p>Translation of Budget: ', t('Budget'), '</p>' ?>


right before

<?= '<p>Current language: ', \Localization::activeLocale(), '</p>' ?>


what gets printed out?
linuxoid replied on at Permalink Reply 1 Attachment
linuxoid
Michele,

All translation I put myself into t() DO get translated, no problem here.

The problem is I have input fields for a user to enter strings. These then get saved in the database. So no user entered text gets translated.

That is, all those categories: Budget, Economy, Luxury are what I entered in the text inputs. These do not get translated.

PS. See the attached pic
mlocati replied on at Permalink Reply
mlocati
I assume that your users enter some English text, and it gets saved into a "category" field in a MY_PACKAGE_DB database table.

For example, a user enters "Budget", and it's saved to the database.

Next, you go to the /dashboard/system/multilingual/translate_interface dasbboard page, hit the "Reload strings" button, translate "Budget" to Russian, and save the translations with "Save to file".

Now concrete5 can translate "Budget" to Russian.

That's it.
It works, please don't try to persuade me that it doesn't work.
I gave you all the informations required to do what you need.
linuxoid replied on at Permalink Reply
linuxoid
That's exactly what I'm doing and it doesn't work. I tried 2 fresh installs, also tried on v8.3.2 and on v8.4.2. Have you seen the pictures? It does NOT work!
mlocati replied on at Permalink Reply
mlocati
Again, it does work! You must be missing some point.

If the user enters "Budget", and you go to the /dashboard/system/multilingual/translate_interface dasbboard page, hit the "Reload strings" button, translate "Budget" to Russian, and save the translations with "Save to file", do you have these lines in the application/languages/site/ru_RU.po file?

msgid "Budget"
msgstr "Russian translation of Budget"
linuxoid replied on at Permalink Reply 2 Attachments
linuxoid
Michele, I've said above and attached pictures that that's what I've done and listed exactly the same steps. See pics here. See the strings English and Russian is in the file, I reloaded the strings, cleared cache... Nothing!

BTW, I'm on a localhost on a PC with Linux and Apache - hope that doesn't matter.
mlocati replied on at Permalink Reply
mlocati
You posted this picture:
https://www.concrete5.org/files/9815/4081/1438/Screenshot_20181029_2...

There I see multiple strings ("Budged", "Economy", "Luxury"): could you post the code that prints them out?
linuxoid replied on at Permalink Reply
linuxoid
<?php foreach ($categories as $category) {
    if ($category->getCategoryID() == $category_id) { ?>
        <li class="active"><a href="<?php echo \URL::to('/cars/categories/', $category->getCategory()); ?>"><?php echo $category->getCategory(); ?></a></li>
    <?php } else { ?>
        <li><a href="<?php echo \URL::to('/cars/categories/', $category->getCategory()); ?>"><?php echo $category->getCategory(); ?></a></li>
    <?php } ?>
<?php } ?>
mlocati replied on at Permalink Reply
mlocati
concrete5 translates strings that are enclosed in t(), but in your code I don't see any t().

You should write something like

<?= t($category->getCategory()) ?>


instead of

<?= $category->getCategory() ?>
linuxoid replied on at Permalink Reply
linuxoid
YES, YES, YES!!! That's it!

I didn't know the dynamic/user string should also be inside t().

Thank you very very much. You saved me.

Maybe you could update the t() documentation page to say that's how it's done?

Thanks a lot again!!! It works now.
mlocati replied on at Permalink Reply
mlocati
As I told you, the system works, you were missing something