babel
Babel is a compiler for writing next generation JavaScript.
Babel · The compiler for writing next generation JavaScript the compiler for writing next generation javascript
I'm writing a lisp program to fetch a web page of a Chinese website, I meet problem about parsing the Chinese words from the binary stream, I already have a vector of (unsigned-byte 8) containing the whole page, but when I put it to the babel:octets-to-string, it throws out an exception.
(setf buffer (babel:octets-to-string buffer :encoding :utf-8))
The exception is:
Illegal :UTF-8 character starting at position 437. [Condition of
type BABEL-ENCODINGS:INVALID-UTF8-CONTINUATION-BYTE]
I fount that when it meet a Chinese word it must throw out this exception. How can I solve it?
Source: (StackOverflow)
I am using Flask, jinja together with Mustachjs.
In order to get the job done I am using the {% raw %} tag.
Now, it is a multi-languages application and I use Babel.
How can I do :
{% raw %}
<script id="details" type="text/template">
<table class="table" >
<thead>
<tr>
<th>**{{gettext('col1')}}</th>
<th>**{{gettext('col2')}}</th>
<th>**{{gettext('col6')}}</th>
</tr>
</thead>
<tbody>
{{#skyrsla}}
<tr>
<td> {{index}}</td>
<td> {{nafn}}</td>
<td> {{mean_growth_index}}</td>
</tr>
{{/skyrsla}}
</tbody>
</table>
</script>
{% endraw %}
Since it is between raw tags, the Babel extension does not detect {{gettext('col1')}
Is there a way to alter the configuration of Babel.
My actual configuration looks like :
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
Source: (StackOverflow)
Pyramid documentation shows us how to use i18n inside views (and templates as well). But how to does one use it outside of views and templates where we have no access to current request
(for example, in forms
and models
)?
@Michael said to pass request
to models and forms. But is it right? I mean if form fields defines before __init__()
method calls, the same with models. They don't see any parameters from views...
In Pylons we could simply use get_lang()
and set_lang()
and define preferable language in parent controller and then use ugettext()
and ungettext()
in any place we want without calling it from request
directly every possible time (in views).
How to do that in Pyramid? Note that the language must be set from user's settings (session, cookies, db, etc).
Source: (StackOverflow)
I am currently trying to use Babel to generate a set of static html pages in different languages using Jinja2 within a simple script (not as part of a web app)
I am at the point where I need to extract the messages for translation and I know that I am supposed to modify the Babel mapping configuration file to understand Jinja2 templates.Since I am using the commandline tool, I assume I need to create the mapping file myself.
However, I can't seem to find in the documentation what the mapping configuration file should be named and where it should be placed. All I know is that I need to place the following:
[jinja2: **/templates/**.html]
encoding = utf-8
into the mapping file according to the Jinja2 documentation. Has anyone done something similar or know what the mapping configuration file should be? Thanks!
Source: (StackOverflow)
I'm using Flask-Babel for translating string.
In some templates I'm reading the strings from the database(postgresql).
How can I translate the strings from the database using Flask-Babel?
Thanks,
Jovanka
Source: (StackOverflow)
I would like to enable auto-complete
for Babel code blocks in org-mode
:
#+begin_src emacs-lisp
(setq ) <--- language-aware auto-completion here
#+end_src
What do I need to add to my .emacs
file in order to configure auto-complete
to do this?
Source: (StackOverflow)
I run a job every hour that can send an email to users. When the email is sent, it needs to be in the language set by the user (saved in the db).
I can't figure out a way to set a different locale outside of a request context.
Here is what I would like to do:
def scheduled_task():
for user in users:
set_locale(user.locale)
print lazy_gettext(u"This text should be in your language")
Source: (StackOverflow)
How would you go about internationalizing a Google App Engine webapp application using BABEL? I am looking here for all the stages:
- Marking the strings to be translated.
- Extracting them.
- Traslating
- Configuring your app to load the right language requested by the browser
Source: (StackOverflow)
In my Flask application, in main.py file, I defined:
from flaskext.babel import gettext
....
def somefun():
return render_template('some.html', messages=messages)
in template file some.html, I used:
<input type='text' name='keywords' value='{{ keywords|default('') }}' placeholder='{{ gettext('Search...') }}' />
This gives an error:
<input type='text' name='keywords' value='{{ keywords|default('') }}' placeholder='{{ gettext('Search...') }}' />
UndefinedError: 'gettext' is undefined
How to import this function for template use?
Source: (StackOverflow)
Babel or pybabel is an interface to the CLDR (Common Locale Data Repository) in Python. As such, it has the same 'knowledge' as PHP's i18n functions and classes (if the appropriate locales are installed on the host), but without the hassle of using process-wide settings like setlocale()
.
Is there a similar library or toolkit for PHP? Especially to achieve:
converting numbers to and fro language and region specific formats
converting dates likewise
accessing names, monetary and other information in a certain locale (like, e.g.
>>> from babel import Locale
>>> locale = Locale('en', 'US')
>>> locale.territories['US']
u'United States'
>>> locale = Locale('es', 'MX')
>>> locale.territories['US']
u'Estados Unidos'
Source: (StackOverflow)
I am utterly confused with trying to use babel with flask for language translation.
Lets assume the following. A user has a preferance of spanish over english. I have a variable that marks this:
g.user.default_language='sp'
Lets say I have to messages, one on english and the other in spanish that I want to display.
'Please' vs 'por fovor'
<html>
<h1>INSERT TRANSLATION HERE</h1>
</html>
Here is my base babel config file
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
So, where does 'Please' go and how is it mapped to 'por fovor' if user pref is spanish?
Then, how to I call from a template based on language profile?
Thanks
Source: (StackOverflow)
I've got an application that runs in several processes (one webserver and few processes that are used for heavy calculations). The goal is to make these calculation processes return localized errors. In order to do that, I've made a dictionary that will be used by Babel:
errors = {
'ERR_REQUEST_FORMAT': (1, _('ERR_REQUEST_FORMAT')),
'ERR_REQUEST_TYPE': (2, _('ERR_REQUEST_TYPE')),
}
But when I try to to launch the application, I get
TypeError: No object (name: translator) has been registered for this thread
What is the right way to load the translator object?
Thanks in advance, Ivan.
Source: (StackOverflow)
I cant get a basic translationto work in Flask Babel.
Here are my steps.
I have this in a page {{_("Hello")}}
I run this command.
pybabel extract -F babel.cfg -o messages.pot .
I then run this command for German.
pybabel init -i messages.pot -d translations -l de
Here is the mo file for german in /app/translations/de/LC_MESSAGES/messages.po
# German translations for PROJECT.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-09-24 03:36+0800\n"
"PO-Revision-Date: 2012-09-24 03:37+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
#: templates/baseh5.html:129
msgid "Hello"
msgstr "Guten Tag"
I run this command.
pybabel compile -d translations
This is what I get.
catalog 'translations/de/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
set this is flask
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
What do I get? I get Hello
. Why did Flask Babel not work? How do I deal with fuzzy? This should have been basic.
Source: (StackOverflow)
Is there any library that can extract gettext messages directly from coffeescript files or do I need to compile them to javascript and extract only then?
I've been using python babel module for message extraction, could be good if coffeescript extraction function existed for it.
Source: (StackOverflow)
I have two assemblies, A and B, where A depends on B. I'm trying to obfuscate both of them together, i.e. in a way it doesn't break the app with the babel obfuscator.
Is there a way to do that? Apparently this obfuscator doesn't handle multiple assemblies.
If that's an issue, which other .NET obfuscator- that handles multiple assemblies- would you recommend?
Source: (StackOverflow)