xfra35 / f3-multilang

Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
GNU General Public License v3.0
48 stars 13 forks source link

How can I add the region ? #19

Closed ursulnegrul closed 5 years ago

ursulnegrul commented 5 years ago

Big fan of your work guys, thank you. My issue, I was wondering if I could do it in the f3 "way" without a custom route controller I wish to have an optional selected region added in the url For example Is possible to implement ? /fr/* as /fr-CH/* or /fr-FR/* where $CH or $FR could be a default $WW (for world wide)

xfra35 commented 5 years ago

Hi!

What about the following configuration?

[MULTILANG.languages]
fr = fr-FR,fr
fr-CH = fr-CH,fr
fr-FR = fr-FR,fr

Is that what you mean?

ursulnegrul commented 5 years ago

wow, thought it would be more difficult than that :) while(true) { Thank you }

xfra35 commented 5 years ago

Glad to help :)

ursulnegrul commented 5 years ago

Back and ugly .. so my configuration to force en-WW as default is

[MULTILANG.languages]
en-WW = en
en-FR = en
en-IT = en
en-DE = en
en-AT = en
en-CH = en

fr-WW = fr
fr-FR = fr
fr-IT = fr
fr-DE = fr
fr-AT = fr
fr-CH = fr

...plus 'de' and 'it'

Problem now is with the rewrite rules, obviously I have to write [MULTILANG.rules.fr-*] for each language and alis .. no quick solution for this ? like a default


[MULTILANG.rules.default.fr]
home = /bienvenue
xfra35 commented 5 years ago

What are you trying to achieve? What's the meaning behind en-DE and fr-AT?

ursulnegrul commented 5 years ago

The guests can select language and region, en-WW is the default (global), behind the scenes only the language is important 'en' for the appropriate templates.

xfra35 commented 5 years ago

What does the choice of "region" bring to the user?

ursulnegrul commented 5 years ago

Just a flag near his username, no other role, it matters ? :)

xfra35 commented 5 years ago

It does :) I don't think you should include the region in the URL if it doesn't bring anything new to the user. Different URLs indicate different contents. If /en-DE and /en-AT display the same content, apart from a flag, then you shouldn't use different URLs. Just call it /en and handle the region flag with a cookie or a browser Storage. If you care about SEO, you'd also avoid duplicate content issues.

ursulnegrul commented 5 years ago

The project may extend and different content may be provided, a "default" fallback rule would have been useful.

xfra35 commented 5 years ago

Ok then a solution for you would be to generate language-region combinations using PHP:

[MULTILANG.languages]
en = en-GB,en-US,en
fr = fr-FR,fr
de = de-DE,de
it = it-IT,it

[MULTILANG.rules.fr]
home = /bienvenue
$languages = &$f3->ref('MULTILANG.languages');
$rules = &$f3->ref('MULTILANG.rules');
$langs = array_keys($languages);
$regions = ['WW','FR','IT','DE','AT','CH'];
foreach ($langs as $lang)
  foreach ($regions as $region) {
    $languages[$lang.'-'.$region] = $languages[$lang];
    $rules[$lang.'-'.$region] = $rules[$lang];
  }
ursulnegrul commented 5 years ago

OK thank you, It works flawlessly.