Comments (11)
I'll try to explain.
Current flask-babel implementation does not support localization domains - there's no way to tell flask-babel to look for translations outside of the global translation cache.
I made a patch to flask-babel and submitted to @mitsuhiko, however he was busy and did not accept it at the time. I made corrections and patch still in pending state.
So, right now, you have to use my customized version of the flask-babel to enable admin translations.
Reason why it silently disables translations - not everyone wants to translate their application, so they might not have flask-babel installed.
from flask-admin.
I've tryed the exemple given here (using Flask-BabelEx): https://github.com/mrjoes/flask-admin/blob/master/examples/babel/simple.py
And it simply didn't work (I mean the texts were in english although my OS (Windows 7) and my navigators are configured for the french language). I tested with both Seamonkey (2.16.2) and Internet Explorer (9).
The only way I found to get the language I wanted was to modify :
def get_locale():
override = request.args.get('lang')if override:
session['lang'] = overridereturn session.get('lang', 'en')
into :
def get_locale():
override = request.args.get('lang')if override:
session['lang'] = overridereturn session.get('lang', 'fr')
which is durty and not adaptable at all, as you can see.
Furthermore, even with this modification, the dates were not properly shows (I was expecting 'day/month/year' format).
Versions:
Flask-Admin 1.0.5
Flask-babelex 0.8.1
Babel 0.9.6
pytz 2013b
speaklater 1.3
from flask-admin.
Idea was that you open your administrative URL with ?lang=fr to switch to French and it will store it in the session.
Sure, in real world application you might want to switch languages differently: have link which will store something in the session, or have special query string parameter for that, etc.
As for dates - yes, DatePicker control that Flask-Admin is using is not localizable at all..
from flask-admin.
Ok, thanks for the precision, it works (I thought that the language of the user was supposed to be detected automatically).
from flask-admin.
I have tried to a add a little menu to make language selection user-frendly, but I failed. Anyway I give you the code, so I hope it will give you some inspiration at least.
I've added this code at the end of flask_admin/templates/admin/layout.html (may sounds stupid for you, but not for me, a complete newbie):
{% macro menu_language() %}
<script type='text/javascript'>
function resetIndex(langObj){
langObj.selectedIndex = -1;
}
function changeLanguage(langObj){
var CurUrl = document.location.href;
SimpleUrl = CurUrl.substring(0 , CurUrl.lastIndexOf( "?" ));
NvUrl = SimpleUrl + '?lang=' + langObj.options[langObj.selectedIndex].value;
document.location.href = NvUrl;
}
</script>
français english русский deutsch
{% endmacro %}
and this in flask_admin/templates/admin/base.html:
{{ layout.menu_language() }}
I'm sorry, I'm just discovering your code, javascript and website developpement. Maybe it would be better to make it with more python, but really it was to hard for me to figure out.
Just a last thing; in trying to modify your code, I noticed that the files were encoded in ASCII. I don't know if it's your code, or github, or my OS, but the best practice seems to be to encode in UTF-8 without BOM, especially when it comes to write "русский" or "français" which, somehow somewhere, as to be in the code (once again, I don't know if you can make something for it, cause I'm just discovering Github as well).
Sorry I can't help you more.
from flask-admin.
As you can see, an element is not translated. I've checked the .po, and there is nothing like '"%(name)" list' in the file to translate. There is just 'List', and I have translated it.
Same goes for Create and Edit :
from flask-admin.
Yes, template does not use gettext methods, as it was more of the example.
You can wrap text with _gettext()
in template and create new entry 'list', like this:
{{ _gettext('list') }}
from flask-admin.
Sorry, I don't understand. In which file do I have to put it (I thought it would be in https://github.com/mrjoes/flask-admin/blob/master/flask_admin/templates/admin/model/list.html but it doesn't seems so)?
from flask-admin.
If you're using custom layout from 'layout' sample, then I assume you also copied templates to your project.
In this case, open copied 'list.html' file look for this line:
<h2 id="brand">{{ admin_view.name|capitalize }} list</h2>
Wrap 'list' with _gettext
from flask-admin.
Ok I see, thanks.
from flask-admin.
Flask-Admin==1.0.8, Flask-BabelEx==0.9.1
Flask-Admin's translation does not work as expected. I also ran the given example https://github.com/mrjoes/flask-admin/tree/master/examples/babel, but the database integrity errors weren't translated.
I find out "Already exits." in flask_admin/contrib/sqla/validators.py, lineno is 38, however, admin.po in translations/fr/LC_MESSAGES indicates that msgid "Aleardy exists." is related to
#: ../flask_admin/contrib/sqla/validators.py:38, not 33. Finally, the gettext(self, string) of DummyTranslations object simple return the value passed in.
Filter operation also display English text rather than French text.
from flask-admin.
Related Issues (20)
- Request for Enhanced Documentation on Overriding ajax_update in Flask-Admin
- mongodb form_subdocument overwrite stopped working after updates to current flask/ flask-admin/ flask-mongoenine HOT 1
- Multiple selection from dropdown list. HOT 1
- Problem with scoped_session by sqlalchemy
- RFE: migrate from `flask-babelex` to `flask-babel`
- Bootstrap4: Duplicate requests when opening modal windows
- Intercepting and executing custom code on object creation/update in flask-admin HOT 2
- How to use form_overrides on ListField(StringField)?
- `rediscli` command names should be treated case-insensitively
- Enhancement: Allow page_size_options = [15,30,60] to override 20,50,100 hard coded into page_size_form layout
- Error launching the examples using Python 3.12 HOT 1
- QueryAjaxModelLoader and additional filters
- Please update the requirements.txt in examples/sqla/ HOT 1
- Can't use column_filters with peewee ForeignKeyField
- aioflask with Flask>=3.0
- Form column is not being displayed if it starts with underscore "_" HOT 7
- Unable to Render Flask-Admin Edit Form Fields for Variables Stored as JSON HOT 1
- Seeking help from additional volunteers? HOT 3
- Creating custom views for BaseView grouped in a category and passing an id
- Can't use multiple `Admin` instances with different Bootstrap themes (`FLASK_ADMIN_SWATCH`) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-admin.