Code Monkey home page Code Monkey logo

flask-babelex's Issues

Translations List

I need to to get translation list for only files that has the domain name "myext.mo" not all the files that ends with ".mo", I tried almost everything but I think there is no way currently.

gettext() issue

I am using flask_babelex module to translate strings in my project earlier I was using flask_babel but with Flask-Security 3.0 it comes pre-bundled and was causing conflicts with flask_babel. So I removed flask_babel and decided to use flask_babelex but it was throwing error, The given scenario below is for English to Japanese translation:

Here is the actual string:

     gettext(
         'The font size to use for the SQL text boxes and editors. '
         'The value specified is in "em" units, in which 1 is the  '
         'default relative font size. For example, to increase the '
         'font size by 20 percent use a value of 1.2, or to reduce '
         'by 20 percent, use a value of 0.8. Minimum 0.1, maximum 10.'
     )

It fails at: ../venv/lib/python3.6/site-packages/flask_babelex/__init__.py +534

with the following error:

File "/Users/admin/Documents/projects/venv/lib/python3.6/site-packages/flask_babelex/__init__.py", line 623, in gettext
   return get_domain().gettext(*args, **kwargs)
 File "/Users/admin/Documents/projects/venv/lib/python3.6/site-packages/flask_babelex/__init__.py", line 534, in gettext
   return t.ugettext(string) % variables

ValueError: unsupported format character '?' (0x5927) at index 70

Screenshot: https://i.stack.imgur.com/dEIHk.png

Merging Flask-BabelEx back into Flask-Babel

After some discussions in the Pallets discord (where people, including myself, actually assumed that BabelEx is dead due to not having had a release in the last 4 years), I'm wondering whether it wouldn't make sense to merge back the changes from Flask-BabelEx into Flask-Babel.

As the lead developer of a project that currently uses Flask-BabelEx and the extra features it has, I'd love to see that happen (since actively maintained libs are nicer to work with, and for something as "core" as i18n having one single lib would make things more straightforward for anyone).

We can actually dedicate some developer time for this, but it would be interesting to hear your opinion on that as well, @mrjoes, since you started the fork in the first place.

Support of multiple domains

I'm using flask_user with babelex. flask_user provides i18n for its registration pages, but not for emails it's sending. I'd like to implement only translations for my custom emails, but not for the standard pages. I can provide my own domain to Babel instance. I'd like flask_user to get email translations from my custom Domain, but fall back to its own on standard pages. Having two Domains -- mine and flask_user's -- how can I merge them to the single domain and pass it to Babel?

KeyError with NumberRange validator

This issue occurs when validators have been added to a Flask-Admin field via the form_args attribute. It appeares when using the NumberRange validator but others might be concerned as well. A false validation of the NumberRange validator will result in a KeyError. This is due to the message string getting passed to gettext with formatting keys but without values.

2017-01-16 21:16:10,570] ERROR in app: Exception on /fabric/edit/ [POST]
Traceback (most recent call last):
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/base.py", line 368, in _run_view
    return fn(self, *args, **kwargs)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/model/base.py", line 1973, in edit_view
    if self.validate_form(form):
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/model/base.py", line 1290, in validate_form
    return validate_form_on_submit(form)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/helpers.py", line 65, in validate_form_on_submit
    return is_form_submitted() and form.validate()
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/form.py", line 310, in validate
    return super(Form, self).validate(extra)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/form.py", line 152, in validate
    if not field.validate(self, extra):
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 204, in validate
    stop_validation = self._run_validation_chain(form, chain)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 224, in _run_validation_chain
    validator(form, self)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/validators.py", line 139, in __call__
    message = field.gettext('Number must be at least %(min)s.')
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 164, in gettext
    return self._translations.gettext(string)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_admin/babel.py", line 55, in gettext
    return wtforms_domain.gettext(string)
  File "/Users/stefan/Documents/python/projects/inventory/venv/lib/python3.6/site-packages/flask_babelex/__init__.py", line 534, in gettext
    return t.ugettext(string) % variables
KeyError: 'min'

missing git release tags

@mrjoes according to 3c9856ff989ff353c8e4ffca1f2fbd2f6fb0b74 and pypi 0.9.4 has been release. However the git tags are not reflecting any releases done. Can you please tag 0.9.4 and future release in git as well? Thanks!

Help - pgAdmin4 fails with AttributeError: 'str' object has no attribute 'gettext'

Starting pgAdmin 4. Please navigate to http://127.0.0.1:5050 in your browser.
2018-03-25 19:41:11,128: ERROR werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 270, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 258, in execute
application_iter = app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in call
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1607, in full_dispatch_request
self.try_trigger_before_first_request_functions()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1654, in try_trigger_before_first_request_functions
func()
File "/usr/share/pgadmin4/web/pgadmin/utils/init.py", line 43, in create_module_preference
self.register_preferences()
File "/usr/share/pgadmin4/web/pgadmin/browser/init.py", line 208, in register_preferences
gettext("Show system objects?"), 'boolean', False,
File "/usr/local/lib/python2.7/dist-packages/flask_babelex/init.py", line 624, in gettext
return get_domain().gettext(*args, **kwargs)
AttributeError: 'str' object has no attribute 'gettext'

Failing test: test_custom_locale_selector

When running test_custom_locale_selector I get errors of the form:

"12. April 2010 um 15:46:00 MESZ" != 12. "April 2010 15:46:00 MESZ"

I am unsure if this is a configuration problem or some underneath library changed. More context can be found at: NixOS/nixpkgs#73074

Fail tests: test_basics, test_custom_locale_selector, test_init_app

Tests fail with the following error:

>>> Test phase: dev-python/flask-babelex-0.9.4
 * python3_6: running distutils-r1_run_phase python_test
F.FF............/usr/lib64/python3.6/site-packages/babel/numbers.py:352: DeprecationWarning: Use babel.numbers.format_decimal() instead.
  warnings.warn('Use babel.numbers.format_decimal() instead.', DeprecationWarning)
.
======================================================================
FAIL: test_basics (__main__.DateFormattingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 38, in test_basics
    '12. April 2010 15:46:00 MESZ'
AssertionError

======================================================================
FAIL: test_custom_locale_selector (__main__.DateFormattingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 98, in test_custom_locale_selector
    assert babel.format_datetime(d) == '12.04.2010 15:46:00'
AssertionError

======================================================================
FAIL: test_init_app (__main__.DateFormattingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 60, in test_init_app
    '12. April 2010 15:46:00 MESZ'
AssertionError

----------------------------------------------------------------------
Ran 17 tests in 0.222s

FAILED (failures=3)

Software versions:

  • dev-python/flask-babelex-0.9.4
  • dev-python/Babel-2.8.0
  • dev-lang/python-3.6.9

The following patch fixes a problem:
https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-python/flask-babelex/files/flask-babelex-0.9.3-tests-fix.patch?id=cc3811adf78b83af1cc2e27a893eae26fc9fc8ad

Not working with Flask-Babel?

I am using two extensions:

Flask-User (which uses Flask-Babel), and
Flask-Admin (which uses Flask-Babelex)

When I try to get i18n working for my application, I am seeing cryptic errors such as:

Traceback (most recent call last):
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/views.py", line 293, in logout
    flash(_('You have signed out successfully.'), 'success')
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/translations.py", line 51, in gettext
    translations = get_translations()
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/translations.py", line 47, in get_translations
    return ctx.flask_user_translations.merge(babel.get_translations())
  File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_babel/__init__.py", line 224, in get_translations
    for dirname in babel.translation_directories:
AttributeError: 'Babel' object has no attribute 'translation_directories'

Is there a guide to integrating both extensions at the same time?

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.