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

Default language hidden from url #12

Open rafatrace opened 8 years ago

rafatrace commented 8 years ago

Hi, how are you?

Is there an option to hide the default language from the url?

Imagine a portuguese app, but also has english translation. 85% of the users are portuguese and 15% aren't. Would make sense to hide /pt since 85% users are portuguese and seeing that in the URL will not matter. Or in the case that I'm building an app that currently supports one language only (but in a near future could turn multilang), so I use Multilang Class thinking about the possibility of having a new language added in the future. If this is the case, all my urls will show /pt although my website only has Portuguese at the moment.

Example urls:

https://my-app.com/ (Portuguese)
https://my-app.com/users (Portuguese)
https://my-app.com/books (Portuguese)
https://my-app.com/books/1 (Portuguese)

https://my-app.com/en (English)
https://my-app.com/en/users (English)
https://my-app.com/en/books (English)
https://my-app.com/en/books/1 (English)

Its probably an aesthetic question, but would be nice to see this implemented. (Since I've faced this problem already).

Cheers.

xfra35 commented 8 years ago

Hey Rafael, I'm fine thanks!

Have you considered setting the migrate flag on? It would automatically permanently redirect /users to /pt/users.

From my experience, leaving primary language URIs untouched can be attractive at the beginning of the localization but makes routing messy on the long term. Also clear language separation at the URI level is said to improve SEO.

Anyway, since this feature has been requested a few times already (cf. issue #5 for example), I'll probably add it some day :P

rafatrace commented 8 years ago

Glad to hear that, I'll reconsider your suggestion. :+1: Thanks ;)

eazuka commented 5 years ago

Hello @xfra35, thanks for the nice job you've done with this f3 multilang plugin.

I also want to use this plugin for a multi-language project and just like others, i also desire that the default language not show in url, so an option to hide the default language from the url would be awesome.

Its going 4yrs since @rafaelsnts opened this issue, I will just like to know if you later added this feature request to hide default/primary/fallback language from the url? if yes, how can it be activated?

SuN-80 commented 4 years ago

I'm not sure why @xfra35 didn't add this option yet, so here is my fork (#24) for those who want to hide subfolder for main language : https://github.com/SuN-80/f3-multilang/blob/master/lib/multilang.php

You can disable the subfolder for main language by setting MULTILANG.hide to TRUE, like this: $f3->set('MULTILANG.hide', TRUE);

sbraaa commented 3 years ago

Hi @xfra35 I'm also interested in the requested feature, any plan to implement it in the near future? By the way, thank you for this usefull plugin!

sbraaa commented 3 years ago

I'm not sure why @xfra35 didn't add this option yet, so here is my fork (#24) for those who want to hide subfolder for main language : https://github.com/SuN-80/f3-multilang/blob/master/lib/multilang.php

You can disable the subfolder for main language by setting MULTILANG.hide to TRUE, like this: $f3->set('MULTILANG.hide', TRUE);

Hi @SuN-80 , I've tried your patch but it doesn't run as expected and I cannot understand what's wrong. in my config.ini I put:

[MULTILANG]
hide=TRUE
;root = /it

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

Italian would be main language but when I try to access it redirects to mydomain/it instead of mydomain/ so I see 404 error (note that MULTILANG.root is commented!).

CACHE is set to FALSE and I deleted all the files in tmp, any advice?

am3000 commented 10 months ago

I'm not sure why @xfra35 didn't add this option yet, so here is my fork (#24) for those who want to hide subfolder for main language : https://github.com/SuN-80/f3-multilang/blob/master/lib/multilang.php You can disable the subfolder for main language by setting MULTILANG.hide to TRUE, like this: $f3->set('MULTILANG.hide', TRUE);

Hi @SuN-80 , I've tried your patch but it doesn't run as expected and I cannot understand what's wrong. in my config.ini I put:

[MULTILANG]
hide=TRUE
;root = /it

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

Italian would be main language but when I try to access it redirects to mydomain/it instead of mydomain/ so I see 404 error (note that MULTILANG.root is commented!).

CACHE is set to FALSE and I deleted all the files in tmp, any advice?

I also had the issue that the home page did not work. I think you can fix it with MULTILANG.root, but I simply changed the last line of the multilang.php from

$this->f3->route('GET /', @$config['root'] ?: function( $f3 ) use ( $self ) {$f3->reroute('/' . $self->current);});

to

if($this->hide!=TRUE || $this->current != $this->primary ) {
     $this->f3->route('GET /', @$config['root'] ?: function( $f3 ) use ( $self ) {$f3->reroute('/' . $self->current);});
}