-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Problems with Language settings #1045
Comments
Just as an update. I created a minimalistic multilingual django project to test the settings and check if it is a suite interference that is disturbing the behavior. Fact is that django behaves exactly the same as the suite does. I have not been able to force a German session from an 'English browser'. I attach the project if someone more proficient in django wants to give it a try without the hassle of creating it. |
Hi @moovida, 🙏 preferably, when you want to report something, use one of provided issue template instead of the "blank one". Additionaly, when in doubt, create multiple issues rather than a single one that describes multiple problems (otherwise over time it will be difficult keep track of what has been solved).
Add this within your custom css: /* HOTFIX FOR: https://github.com/g3w-suite/g3w-admin/issues/1045 */
.nav-links > li:last-child > .dropdown-menu {
right: 0;
left: auto;
} |
Hi @Raruto , sorry for the blank template, has been a miss of my side. Regarding the multiple issues, I find these problems to be all part of the same. Regarding the custom css, thanks, but I assume there a possible generic solution without custom.css? |
Currently ([email protected]), this is a edge case, as you first need to know how to manually edit the For a "no code" solution, the "admin user" should first be able to choose the languages that wants to activate directly from the dashboard: Furthermore, as your application grows, you may want to add more links to the navigation menu (or change the default order). Through custom css/js you can achieve this quickly and without waiting for a new release. That said, keep in mind that this are still one-time configs. Everything can be improved, any further help in coding it is always welcome. |
The reason I am actually asking this if because I am trying to widen the branding documentation page I set up: https://github.com/g3w-suite/g3w-suite-documentation/blob/dev/branding.md I wanted to add the language part to make it more complete, but it seems that setting a default language is not possible (at least I have not been able even in the plain django project, which would be nice if someone could check @wlorenzetti ) and setting just one language has bit of a hassle. It is fine to me to also leave that part out and take it as currently not feasible. |
@moovida This is what I see locally: # settings_docker.py
LANGUAGE_CODE = 'it'
LANGUAGES= (
('it', 'Italiano'),
)
MODELTRANSLATION_DEFAULT_LANGUAGE = 'it' It's a custom branch * I'm working on, but as you can see the language selector doesn't appear. * ie. UI is slightly different (and not yet synced with: #1041) |
Hi @Raruto , I am not sure if I am not seeing something. As I mentioned in the first issue, this is what happens also to me. Setting:
does work properly (apart of the menu glitch). But the important thing discussed previously with Walter, was if there is a possibility to force a language using the settings. |
@moovida Try something like this (it can be improved, not the best place to make changes..): config/g3w-suite/settings_docker.pyLANGUAGE_CODE = 'it'
# LANGUAGES= (
# ('it', 'Italiano'),
# )
# MODELTRANSLATION_DEFAULT_LANGUAGE = 'it' g3w-admin/base/settings/__init__.py...
MIDDLEWARE = ['core.i18n_middleware.i18n_middleware'] + MIDDLEWARE + G3WADMIN_MIDDLEWARE
... g3w-admin/core/i18n_middleware.py# Based on: https://gist.github.com/vstoykov/1366794?permalink_comment_id=3649179#gistcomment-3649179
from contextlib import suppress
from django.conf import settings
def i18n_middleware(get_response):
"""
Ignore Accept-Language HTTP headers.
This will force the I18N machinery to always choose settings.LANGUAGE_CODE
as the default initial language unless another one is set via sessions or cookies.
Should be installed *before* any middleware that checks
request.META['HTTP_ACCEPT_LANGUAGE'], namely
`django.middleware.locale.LocaleMiddleware`.
"""
def middleware(request):
lang = getattr(settings, 'LANGUAGE_CODE')
accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '').split(',')
with suppress(ValueError):
# Remove `lang` from the HTTP_ACCEPT_LANGUAGE to avoid duplicates
accept.remove(lang)
accept = [lang] + accept
request.META['HTTP_ACCEPT_LANGUAGE'] = f"""{','.join(accept)}"""
return get_response(request)
return middleware |
Uhhh, nice one @Raruto This works well. I could add this as a section to the branding page. Do you think a proposal could be made to add a LANGUAGE_FORCE_CODE to the settings that would then enable the use of i18n_middleware: langForce = getattr(settings, 'LANGUAGE_FORCE_CODE')
if langForce:
MIDDLEWARE = ['core.i18n_middleware.i18n_middleware'] + MIDDLEWARE + G3WADMIN_MIDDLEWARE
else:
MIDDLEWARE = MIDDLEWARE + G3WADMIN_MIDDLEWARE and then use the LANGUAGE_FORCE_CODE later in the i18n_middleware. I am honestly not sure what can be done inside an init file. |
IMHO, for these kind customizations (ie. on production sites) would be better to first try to write an own python plugin (like WordPress' child themes) and keep the necessary changes in there. * Every time a new version is released, for a casual user, the settings_docker.py (and the entire docker repository) can become quite difficult to keep aligned (ie. think about upgrading
I don't know if it's that painless (it should be tested with other apps too), better if sponsored. * here you can see an example app that test/add a your own custom
You can also reason in a similar way for changing other For more info: |
Hm, that sounds actually like a clean way to go. Can you elaborate on that? |
Sorry @Raruto , tried to edit the above comment since it started too early, but was not allowed to submit the changes. I will dig into the portal plugin to see if that answeres all my questions. Thank you |
Yes, there are many possibilities to create a plugin:
You can take also look at the following: g3w-admin-ps-timeseries to understand how a Django plugin works. It's the simplest one I can think of (ie. which does not require compiling JS code). |
Let me open an issue about the problems with language settings, so that they can be sorted out in future.
Forcing a default language doesn't seem to be possible at the moment. Let's assume I want to load German by default.
I tried setting:
but nothing changes.
One option, where applicable, is to remove all other languages, so that would lead to a setting like:
This actually breaks the server:
probably because the MODELTRANSLATION_DEFAULT_LANGUAGE is set to 'en' by default. In fact adding:
makes things work. It actually also properly removes the languages combobox, which makes sense, but with the new nice UI, this makes the admin menu fall out of the browser window:
The text was updated successfully, but these errors were encountered: