New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept different country variants #11
Comments
So this only affects the I would not extend this to the URL language detection (like |
My simple web site supports en (the default en-US) and de, es, and pt languages (homewebtest.com). For a quick (ugly) workaround I have now added ALL variants of those 4 languages in lower case AND upper case to the $languages array. If you don't add all variants of for example 'en', then someone who has his browser language set to 'en-au' will get a 404 error page from Yii. If you replace a supported language (for example 'es-ES') with a not supported language (which is not included in $languages, for example 'fr'), you get an url like 'es-ES/fr/...' which gives you another 404 error page. I would prefer to get the page in the default language without error instead. My simple web site does not yet use the Yii2 formatter. I fear the formatter might need the country part of the locale in upper case, as documented in the ICU description (userguide.icu-project.org/locale#TOC-The-Locale-Concept). |
Hmm.. I obviously clicked the wrong button. I did not intend to close the whole issue.. |
Not sure if I understand, but why don't you configure only the country and map it to the full code:
It seems we are now mixing several issues into one here:
|
The mapping 'at' => 'de-AT' etc. might be a better solution than my workaround. Let me try it... I agree with the 3 cases. |
Sorry to inform you that the mapping ['en' => 'en-US', 'de' => 'de-DE', 'es' => 'es-ES', 'pt' => 'pt-PT'] is not enough: the language variants are not recognized. |
If you configure |
Actually, it was your suggestion to map the languages like that, wasn't it? I have some friends in down under and their browser just sends 'en-au' as acceptable language... |
Yes, but why do you still use something like |
well if i do that for all the language variants, then I have the same long list as my current workaround. |
That's unavoidable. The extension needs to know, which languages are supported. So you need to list them explicitely. |
Maybe I still don't completely understand your problem. Could you maybe provide some simple examples? Each with the following information:
|
@rolblo12 I've added a little fix that could improve the situation. Say you have the following language configuration:
And someone sends a request with the following header:
Now it will search the following combinations:
And use the first one that is found. Maybe you could help test this? It's on master. |
Thanks for your fix. TestI uploaded the fix to my test site, but left the configuration as is (all language variants (upper and lower case) of en, de, es, and pt are still in the
Database languageI am working on another webapp, that stores timestamps in MySQL integer columns. I have to convert these integers to human readable dates. Especially for filter criteria, I use now FROM_UNIXTIME() to compare them with the user's filter value. This only works correctly, if I run the SQL statement Therefore I will need a fallback from the language code alone to a reasonable language variant as well. Or maybe the possibility to forbid locales without country variant.. |
About your questions:
About your DB problem: I think you need to solve this in your code. Like: Check the value of |
Regarding 1: You are right, Nevertheless, thank you very much for your extension. |
I will have another look at this. So unless you are in a hurry, you can wait for a fix. I just don't want to rush it and consider all the possible implications, before I work on a fix. |
How about this: We add a two new options: The same will be in effect for autodetecting the language from browser settings. What do you think, would this solve your problem? |
After more thinking maybe this is a better idea: We allow to use Regarding the fallback to the default language I'l open another issue, as this is something different and I want to keep the discussion a bit more focussed on one problem at a time :) |
The possibility to use Regarding a fall-back, I could imagine to have Easier to configure would be to have only |
Sorry, what do you mean by fallback? Is that what I have now moved to #12? The So in your case you would only have a couple of |
Yes, the less configuration, the better. Actually you have the default 'translation' texts anyways, so |
@rolblo12 I've pushed the updated version. Maybe you can help testing again? |
Thank you for the update. The Home Web Test Team is at your service ;-) Have grabbed the latest Test
The language switch in the index page only shows the English choice (because it relies on the entries
Set Firefox to accept
|
Ok, another update. Your points 4-6 above should be fixed now. The error in 7) was in spanish, because you probably still had the language in your session / cookie. |
Just pushed another little fix, so I hope, you didn't test yet :). Note: I've also very much improved the test cases now. They should cover pretty much every possible aspect of the component. All the tests succeed. So maybe also take a look there if you think something is still not behaving correctly. |
No, I'm starting now.. We have siesta here in Spain ;-) |
Crossing fingers here (and may have beer soon as it's usual in German ;)). BTW thanks for your help so far and for the inspiration to this new feature. It also motivated me to finally write some thorough tests for this extension which already helped me to locate a couple of not so nice bugs. So after all I feel much safer now, when it comes to the quality and reliability of the component. |
Test
|
I have seen your unit tests. In PHP I have not yet tried to write unit tests, although in Java I was quite keen to do so ;-) |
Unbelievable how many bugs there can be in such a simple piece of code. Added more test cases and fixed more issues. I start to wonder how all this worked at all before. :D Problem 1) should also be fixed now. About your issue 8) and 2) of your second run: I still consider them invalid use cases, but please keep the discussion for them in #12. They are really a different story. Let's try to cleanly solve this part of the problems here first. Apart from that I think you should change your So maybe you're in the mood for another test run. I'm confident that we're close to solving this issue here. |
Actually I had both |
Not sure, how this is related to the language switcher. :) The important part is really, that you start with a clean |
Well, it my own hand-crafted language switcher ;-) It just shows country flags and optionally the language's name. I use that in the index page only. Nevertheless it would be good to have some unobtrusive dropdown button for the main menu bar to switch languages. |
Well, as I've said in the README this is too specific. It can vary a lot, how such a dropdown looks, which languages it lists, how they are called etc. That's why I only gave a simple example there. So for now, could we please focus on the
or maybe even only:
The |
Ah, so I could just use my 'flag'-languages |
Test
|
No, you misunderstood. If you list |
Test
|
I'm still a bit confused, what you want to achieve in the end. I think, you would not need the So can you provide two lists:
|
continue test
BTW: are the language codes internally
Well, I suppose to catch the last case, you have to forbid controller ids that can be confused with language codes. |
I am aware, that the pure language switch is that simple, because I just provide the translations for the base languages. There is no separate translation for 'de-DE' and 'de-AT' in my webapp. However, regarding other things that come with the country specification makes me tend to have the full country variant internally. Just think about different date representations: de-DE has Januar, de-AT has Jänner. You get those things for free, no additional translation needed. |
I think, we have to come to an end with this issue. The extension now supports many different things, but still it can't do magic. I'll try to sum up all that is possible now with a complex example:
This configuration will do the following:
This should give you now many ways how to configure things. Apart from that I don't think there's more we can do here. So I'll close this issue here for now. If you still think, we can improve things, then maybe come up with a similar list as above and explain exactly what accepted language should lead to which URL and set which language in Yii. |
I think you have provided a very useful extension. Thank you very much! |
Ok, just released version 1.0.5 with all the above changes. Thanks again for your help. |
Requests from Firefox include the language code including any country codes completely in lower case. Localeurls just uses this code as is to set the Yii language.
This is ok for language only. However, if you have country specific language variants, Yii specifies them as upper case (ISO-3166). Also ICU requires the country codes as upper case. Furthermore, if you use the JUI Datepicker, its language specific javascript files have the country code in upper case in their name.
So I suppose converting any country code to upper case before it goes into the Yii language would help.
Another issue is that Localeurls does not fall back from an unsupported language variant to the language without variant. So if I support the 'de' translation, I get an page not found error if the request has 'de-at' as the language code. It could silently switch to 'de' instead.
The text was updated successfully, but these errors were encountered: