vojtasvoboda / oc-twigextensions-plugin

Twig extensions plugin for OctoberCMS
MIT License
18 stars 26 forks source link

Multi language trasnlation not work #20

Closed ribsousa closed 6 years ago

ribsousa commented 7 years ago

I'm having a problem with multi language site!

exemple: post published in 12/1/2017 09:25

Locale set to en works fine! print correct 12 hours ago

When I change language to pt-br not work! print worong 1 hora atrás

'timezone' => 'UTC',

vojtasvoboda commented 7 years ago

But last time (https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/8) you fixed it, don't you?

bastihilger commented 7 years ago

If I may interrupt - there is something wrong in the pt-br language files. I made the same mistake in the German ones. Only the plural versions have had a placeholder. I just created a pull request to fix that.

vojtasvoboda commented 7 years ago

Thanks @manogi it may be solution. @ribsousa can you please test it on your website?

But it's weird, first section should be for singular version.

bastihilger commented 7 years ago

You are right, when I think about it - it should actually just take the plural version.

bastihilger commented 7 years ago

I'm sorry, my comment was wrong - the English files also just have the "1" and no placeholder, and that is perfectly fine like that. So the issue must lie somewhere else.

vojtasvoboda commented 7 years ago

And when you have sites in en and de locale, do they have same results? For example when you can see in English "1 hour ago", do you see same in German one?

ribsousa commented 7 years ago

I have not tested yet if the problem only occurs with pt-br, I will enable German to verify this

ribsousa commented 7 years ago

'timezone' => 'UTC', In German returned the same result as English

The problem then is in pt-br?

ribsousa commented 7 years ago

See! site change language

vojtasvoboda commented 7 years ago

Which is the official timezone for PT-BR? Is it same like English and German?

ribsousa commented 7 years ago

No, Time Zone Brazil

vojtasvoboda commented 7 years ago

And when you set CMS timezone to Brazil, it prints correct translation?

ribsousa commented 7 years ago

set 'timezone' => 'Brazil/East', en/de print ok! 22 hours ago pt-br print 1 hour ago

bastihilger commented 7 years ago

Maybe we should have a look at the actual lang/pt-br/lang.php file in use here...

ribsousa commented 7 years ago

You can check the result here

vojtasvoboda commented 7 years ago

I don't really know. The translations are taken from https://github.com/KnpLabs/KnpTimeBundle/tree/master/Resources/translations so they should be fine.

This plugin only connect October Translator with Twig Extensions plugin. It doesn't modify the data in any way, so I'm not sure. Maybe the problem is in Twig Extensions.

bastihilger commented 7 years ago

It seems it always takes the singular version instead of the plural version.

The lang file in your repository looks fine. But maybe @ribsousa isn't really using that version? Is that an OctoberCMS installation or something else?

ribsousa commented 7 years ago

October clean install!

vojtasvoboda commented 7 years ago

Which build? Try to enable edgeUpdates at config.

bastihilger commented 7 years ago

I just tested this in one of my websites - I have the same problems with pt-br. But now can tweak the files and test better...

bastihilger commented 7 years ago

If I replace the complete content of pt-br with the en lang file, I still get the same wrong results

bastihilger commented 7 years ago

We are getting closer: if I rename "pt-br" to "pt" and use that, it works correctly.

ribsousa commented 7 years ago

pt is Portuguese from Portugal

bastihilger commented 7 years ago

I know - this is not about that, but about the fact that probably the "-" in the folder name is a problem. I could also have renamed it to "xy".

ribsousa commented 7 years ago

ok!

bastihilger commented 7 years ago

An underscore also works: renaming the folder to "pt_br" also had good results. I will prepare a pull request. I guess @vojtasvoboda will merge it and put it on the market place.

Just make sure that after updating the twig extensions plugin you go directly to your language settings in octoberCMS and replace "pt-br" with "pt_br". And the css class of your flag to "flag-icon-pt_br" ;-)

vojtasvoboda commented 7 years ago

This is weird, OctoberCMS uses also pt-br:

With pt_br it will not be compatible with OctoberCMS locale settings.

bastihilger commented 7 years ago

Ah ok - closed my pull request. But then I'm out of my depth here and you need to take over ;-)

Maybe the knowledge that it works without the dash in the folder name helps a little.

bastihilger commented 7 years ago

OK found it - but it is unfortunately a problem with OctoberCMS. It makes use of this class But have a look at line 38: it checks if the locale name is longer than 3 characters and then tries to split it at the "_" sign. After that, the locale is basically empty, and the translation falls back to taking the first part of the string in your translation file. So OctoberCMS also should not be using "pt-br" and so on. But it probably never caused problems, because none of these files seem to use the singular/plural version of translation files...

vojtasvoboda commented 7 years ago

And can you report this behaviour directly to the October repository and mention this thread? I'm curious about solution :-)

ribsousa commented 7 years ago

+1

ribsousa commented 7 years ago

Actually renaming the folder to pt_br and changing the language setting to pt_br, it works. However octobercms uses pt-br; the problem seems to be even the "-" as reported by manogi.

vojtasvoboda commented 7 years ago

I'll wait for @manogi and his Issue to the OctoberCMS repo and we'll see where is the problem.

bastihilger commented 7 years ago

Reported it here.

vojtasvoboda commented 7 years ago

Thanks!