Giter Club home page Giter Club logo

Comments (11)

mrjoes avatar mrjoes commented on May 21, 2024

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.

CeReynAud avatar CeReynAud commented on May 21, 2024

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'] = override

return session.get('lang', 'en')

into :

def get_locale():
override = request.args.get('lang')

if override:
session['lang'] = override

return 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.

mrjoes avatar mrjoes commented on May 21, 2024

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.

CeReynAud avatar CeReynAud commented on May 21, 2024

Ok, thanks for the precision, it works (I thought that the language of the user was supposed to be detected automatically).

from flask-admin.

CeReynAud avatar CeReynAud commented on May 21, 2024

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.

CeReynAud avatar CeReynAud commented on May 21, 2024

flask-admin-babelex-list
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 :
flask-admin-babelex-create
flask-admin-babelex-edit

from flask-admin.

mrjoes avatar mrjoes commented on May 21, 2024

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.

CeReynAud avatar CeReynAud commented on May 21, 2024

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.

mrjoes avatar mrjoes commented on May 21, 2024

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.

CeReynAud avatar CeReynAud commented on May 21, 2024

Ok I see, thanks.

from flask-admin.

hoiming avatar hoiming commented on May 21, 2024

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.

60a94cb0-9af5-4ef5-a9ef-9b932caf1197

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.
60ae5a14-6fec-44e8-bf30-7e608588258b

from flask-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.