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

translation issues #32

Closed
redouane opened this issue Jul 1, 2012 · 11 comments
Closed

translation issues #32

redouane opened this issue Jul 1, 2012 · 11 comments

Comments

@redouane
Copy link
Contributor

redouane commented Jul 1, 2012

flask-admin uses babel domains, which are not yet on the official flask-babel repo ( i think mrjoes sent a pull request 3 months ago)
as a result of that, flask-admin currently cannot be translated, unless you fork, or clone/use mr joes flask-babel fork or wait for flask-babel to pull mrjoes commits.

this dependency / issue isnt documented anywhere, and flask-admin does not complain about the them not being implemented, and instead defaults to the currently set strings.

tl;dr : why implement it that way, ( dependency on not yet pulled to official flask-babel repo ) ?

thanks.

@mrjoes
Copy link
Contributor

mrjoes commented Jul 1, 2012

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.

@CeReynAud
Copy link
Contributor

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

@mrjoes
Copy link
Contributor

mrjoes commented Mar 25, 2013

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

@CeReynAud
Copy link
Contributor

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

@CeReynAud
Copy link
Contributor

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.

@CeReynAud
Copy link
Contributor

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

@mrjoes
Copy link
Contributor

mrjoes commented Mar 28, 2013

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') }}

@CeReynAud
Copy link
Contributor

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)?

@mrjoes
Copy link
Contributor

mrjoes commented Mar 28, 2013

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

@CeReynAud
Copy link
Contributor

Ok I see, thanks.

@mrjoes mrjoes closed this as completed Apr 5, 2013
@hoiming
Copy link

hoiming commented Apr 30, 2014

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

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

No branches or pull requests

4 participants