Skip to content
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

A Minor Drawback #10

Closed
jmp0xf opened this issue Feb 5, 2015 · 16 comments
Closed

A Minor Drawback #10

jmp0xf opened this issue Feb 5, 2015 · 16 comments

Comments

@jmp0xf
Copy link

jmp0xf commented Feb 5, 2015

If SOLID_I18N_USE_REDIRECTS is set to be True, the url containing default language code would be unable to route, which is not a friendly behaviour in my opinion.

@st4lk
Copy link
Owner

st4lk commented Feb 6, 2015

Hi, thanks for reporting!
What do you mean by "unable to route"? It is about the case, when client have language other than default language of web application and he'll get redirect 301 or 302?
But exactly this behaviour you get, if SOLID_I18N_USE_REDIRECTS = True.
By the way, default django i18n process will always return 301 or 302 redirect if you request url without language code.

@jmp0xf
Copy link
Author

jmp0xf commented Feb 6, 2015

eg. The default language code is "en". Trying to access http://example.com/en will get you a 404 response.
A better behaviour should be redirecting it to http://example.com with setting current language to "en"

@st4lk
Copy link
Owner

st4lk commented Feb 6, 2015

Ah, agree, that make sense

st4lk added a commit that referenced this issue Feb 16, 2015
@st4lk
Copy link
Owner

st4lk commented Feb 16, 2015

One note: If prefix with default language code is present in url, exactly that language will be rendered, redirect will not occur.
Uploaded version v0.6.1

@st4lk st4lk closed this as completed Feb 16, 2015
This was referenced Feb 18, 2015
@st4lk
Copy link
Owner

st4lk commented Feb 23, 2015

@jmp0xf i've added some settings to control default language prefix behaviour #12 .
Probably you'll be interested in SOLID_I18N_DEFAULT_PREFIX_REDIRECT = True.
This setting is available in v0.7.1 from pypi.

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

it seems that it cannot work properly with SOLID_I18N_USE_REDIRECTS = True
Precisely, it cannot change current language by visiting url with default language code prefix.

@st4lk
Copy link
Owner

st4lk commented Feb 25, 2015

Precise, what behaviour do you expect and what you get?

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

it is able to show the page in proper language when SOLID_I18N_USE_REDIRECTS = True. However the language setting will not be changed.
if both SOLID_I18N_USE_REDIRECTS and SOLID_I18N_DEFAULT_PREFIX_REDIRECT are set to be True, visiting url with default language prefix will redirect to url with current language prefix.

@st4lk
Copy link
Owner

st4lk commented Feb 25, 2015

You mean, when

LANGUAGE_CODE = 'en'  # default language
LANGUAGES = (('ru', 'Russian'), ('en', 'English'))

url /en/... must render english content in every case, even if preferred language is Russian?
In that case you should not use SOLID_I18N_DEFAULT_PREFIX_REDIRECT = True, use SOLID_I18N_HANDLE_DEFAULT_PREFIX = True instead.

I don't think, that by accessing to url /en/ we must set in client's cookies preferred language = English.
To my mind, it must be done explicitly by user by clicking corresponding button.

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

Of course the actual strategy is a personal opinion. However, changing preferred language in terms of language prefix in url is the behaviour for non-default language prefix. I think it is better to keep consistent.

@st4lk
Copy link
Owner

st4lk commented Feb 25, 2015

Preferred language is never changed implicitly. If i understand you correctly, you mean that by accessing url with non-default language prefix, i.e. /ru/..., we somehow change user's preferred language. But it is not. Language prefix just have higher priority over user's preferences in discovering language for current request.
By default in django (without solid-i18n), when you access /ru/ url you'll always get Russian content. Even if your preferred language is English. But url / will redirect you to /en/.

solid-i18n follows this strategy, except when both settings SOLID_I18N_DEFAULT_PREFIX_REDIRECT and SOLID_I18N_USE_REDIRECTS are set to True. In that case you can't see English content just by visiting /en/ url. You need to set your preferred language explicitly first (by sending POST to set_language view).

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

My fault, the url with language prefix does not change the language setting, and yes, it should not do that. The actual problem annoying me lies in reversing named URLs in my observation. With SOLID_I18N_HANDLE_DEFAULT_PREFIX = True, the named url cannot be parsed to contain corresponding language prefix in rendered page with default language prefix in url. However, a non-default language prefixed page can handle it properly.

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

My problem lies in

if language_code != settings.LANGUAGE_CODE:
                regex = '^%s/' % language_code
            elif getattr(settings, 'SOLID_I18N_HANDLE_DEFAULT_PREFIX', False):
                regex = '(?:^%s/)?' % language_code
            else:
                regex = ''

If I change it to

if language_code != settings.LANGUAGE_CODE:
                regex = '^%s/' % language_code
            elif getattr(settings, 'SOLID_I18N_HANDLE_DEFAULT_PREFIX', False):
                regex = '^%s/' % language_code
            else:
                regex = ''

Everything goes fine.

@st4lk
Copy link
Owner

st4lk commented Feb 25, 2015

LANGUAGE_CODE = 'en'
LANGUAGES = (('ru', 'Russian'), ('en', 'English'))

urlpatterns = solid_i18n_patterns('',
    url(r'^$', home_view, name='home'),
    url(r'^about/$', about_view, name='about'),
)
SOLID_I18N_HANDLE_DEFAULT_PREFIX = False
    with translation.override('en'):
        url = reverse('about')  # /about/
    with translation.override('ru'):
        url = reverse('about')  # /ru/about/
SOLID_I18N_HANDLE_DEFAULT_PREFIX = True
    with translation.override('en'):
        url = reverse('about')  # /about/
    with translation.override('ru'):
        url = reverse('about')  # /ru/about/

What you need instead of this?

You mean, that when make request to url without language prefix, reverse all other urls without prefix.
And when we request url with default language prefix, reverse all other urls with default language prefix?

@st4lk
Copy link
Owner

st4lk commented Feb 25, 2015

By the way, this code:

if language_code != settings.LANGUAGE_CODE:
                regex = '^%s/' % language_code
            elif getattr(settings, 'SOLID_I18N_HANDLE_DEFAULT_PREFIX', False):
                regex = '^%s/' % language_code
            else:
                regex = ''

will respond 404 for root urls (without language prefix), if SOLID_I18N_HANDLE_DEFAULT_PREFIX = True.

@jmp0xf
Copy link
Author

jmp0xf commented Feb 25, 2015

Yes, I was trying to say "when make request to url without language prefix, reverse all other urls without prefix and we request url with default language prefix, reverse all other urls with default language prefix"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants