Google App Engine - Python - Babel - write_mo()
I'm working on Google App Engine Python3.7
I wrote this working code based on what I learned here:
http://babel.pocoo.org/en/latest/api/messages/mofile.html
https://docs.python.org/3/library/gettext.html#gettext.NullTranslations.install
import babel
from babel.messages import Catalog
from babel.messages.mofile import write_mo
import gettext
_ = gettext.gettext
from gettext import GNUTranslations
from babel._compat import BytesIO
logging.info(_('gg'))
catalog = Catalog(locale='en_US', domain='myapp')
catalog.add('foo', 'Voh')
catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
catalog.add('fuz', 'Futz', flags=['fuzzy'])
catalog.add('Fizz', '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
logging.debug(catalog)
logging.debug(catalog['foo'].string)
buf = BytesIO()
write_mo(buf, catalog)
buf.seek(0)
translations = GNUTranslations(fp=buf)
logging.debug(translations.gettext('foo'))
logging.debug(translations.ngettext('bar', 'baz', 1))
logging.debug(translations.ngettext('bar', 'baz', 2))
logging.debug(translations.gettext('fuz'))
logging.debug(translations.gettext('Fizz'))
logging.debug(translations.gettext('Fuzz'))
logging.debug(translations.gettext('Fuzzes'))
logging.debug(_('foo'))#this returns 'foo'
Then i tried to add:
lang1 = gettext.translation('myapp', languages=['en'])
lang1.install()
logging.debug(_('foo'))
but it doesn't work. It raises the Error:
FileNotFoundError: [Errno 2] No translation file found for domain: 'myapp'
python-3.x google-app-engine babel
add a comment |
I'm working on Google App Engine Python3.7
I wrote this working code based on what I learned here:
http://babel.pocoo.org/en/latest/api/messages/mofile.html
https://docs.python.org/3/library/gettext.html#gettext.NullTranslations.install
import babel
from babel.messages import Catalog
from babel.messages.mofile import write_mo
import gettext
_ = gettext.gettext
from gettext import GNUTranslations
from babel._compat import BytesIO
logging.info(_('gg'))
catalog = Catalog(locale='en_US', domain='myapp')
catalog.add('foo', 'Voh')
catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
catalog.add('fuz', 'Futz', flags=['fuzzy'])
catalog.add('Fizz', '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
logging.debug(catalog)
logging.debug(catalog['foo'].string)
buf = BytesIO()
write_mo(buf, catalog)
buf.seek(0)
translations = GNUTranslations(fp=buf)
logging.debug(translations.gettext('foo'))
logging.debug(translations.ngettext('bar', 'baz', 1))
logging.debug(translations.ngettext('bar', 'baz', 2))
logging.debug(translations.gettext('fuz'))
logging.debug(translations.gettext('Fizz'))
logging.debug(translations.gettext('Fuzz'))
logging.debug(translations.gettext('Fuzzes'))
logging.debug(_('foo'))#this returns 'foo'
Then i tried to add:
lang1 = gettext.translation('myapp', languages=['en'])
lang1.install()
logging.debug(_('foo'))
but it doesn't work. It raises the Error:
FileNotFoundError: [Errno 2] No translation file found for domain: 'myapp'
python-3.x google-app-engine babel
Can you share the directory structure for your app? Do you have amyapp.mo/myapp.pofile for your domain?
– Dustin Ingram
Jan 3 at 21:35
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44
add a comment |
I'm working on Google App Engine Python3.7
I wrote this working code based on what I learned here:
http://babel.pocoo.org/en/latest/api/messages/mofile.html
https://docs.python.org/3/library/gettext.html#gettext.NullTranslations.install
import babel
from babel.messages import Catalog
from babel.messages.mofile import write_mo
import gettext
_ = gettext.gettext
from gettext import GNUTranslations
from babel._compat import BytesIO
logging.info(_('gg'))
catalog = Catalog(locale='en_US', domain='myapp')
catalog.add('foo', 'Voh')
catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
catalog.add('fuz', 'Futz', flags=['fuzzy'])
catalog.add('Fizz', '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
logging.debug(catalog)
logging.debug(catalog['foo'].string)
buf = BytesIO()
write_mo(buf, catalog)
buf.seek(0)
translations = GNUTranslations(fp=buf)
logging.debug(translations.gettext('foo'))
logging.debug(translations.ngettext('bar', 'baz', 1))
logging.debug(translations.ngettext('bar', 'baz', 2))
logging.debug(translations.gettext('fuz'))
logging.debug(translations.gettext('Fizz'))
logging.debug(translations.gettext('Fuzz'))
logging.debug(translations.gettext('Fuzzes'))
logging.debug(_('foo'))#this returns 'foo'
Then i tried to add:
lang1 = gettext.translation('myapp', languages=['en'])
lang1.install()
logging.debug(_('foo'))
but it doesn't work. It raises the Error:
FileNotFoundError: [Errno 2] No translation file found for domain: 'myapp'
python-3.x google-app-engine babel
I'm working on Google App Engine Python3.7
I wrote this working code based on what I learned here:
http://babel.pocoo.org/en/latest/api/messages/mofile.html
https://docs.python.org/3/library/gettext.html#gettext.NullTranslations.install
import babel
from babel.messages import Catalog
from babel.messages.mofile import write_mo
import gettext
_ = gettext.gettext
from gettext import GNUTranslations
from babel._compat import BytesIO
logging.info(_('gg'))
catalog = Catalog(locale='en_US', domain='myapp')
catalog.add('foo', 'Voh')
catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
catalog.add('fuz', 'Futz', flags=['fuzzy'])
catalog.add('Fizz', '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
logging.debug(catalog)
logging.debug(catalog['foo'].string)
buf = BytesIO()
write_mo(buf, catalog)
buf.seek(0)
translations = GNUTranslations(fp=buf)
logging.debug(translations.gettext('foo'))
logging.debug(translations.ngettext('bar', 'baz', 1))
logging.debug(translations.ngettext('bar', 'baz', 2))
logging.debug(translations.gettext('fuz'))
logging.debug(translations.gettext('Fizz'))
logging.debug(translations.gettext('Fuzz'))
logging.debug(translations.gettext('Fuzzes'))
logging.debug(_('foo'))#this returns 'foo'
Then i tried to add:
lang1 = gettext.translation('myapp', languages=['en'])
lang1.install()
logging.debug(_('foo'))
but it doesn't work. It raises the Error:
FileNotFoundError: [Errno 2] No translation file found for domain: 'myapp'
python-3.x google-app-engine babel
python-3.x google-app-engine babel
asked Jan 3 at 17:58
Paolo177Paolo177
12210
12210
Can you share the directory structure for your app? Do you have amyapp.mo/myapp.pofile for your domain?
– Dustin Ingram
Jan 3 at 21:35
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44
add a comment |
Can you share the directory structure for your app? Do you have amyapp.mo/myapp.pofile for your domain?
– Dustin Ingram
Jan 3 at 21:35
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44
Can you share the directory structure for your app? Do you have a
myapp.mo/myapp.po file for your domain?– Dustin Ingram
Jan 3 at 21:35
Can you share the directory structure for your app? Do you have a
myapp.mo/myapp.po file for your domain?– Dustin Ingram
Jan 3 at 21:35
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027456%2fgoogle-app-engine-python-babel-write-mo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027456%2fgoogle-app-engine-python-babel-write-mo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you share the directory structure for your app? Do you have a
myapp.mo/myapp.pofile for your domain?– Dustin Ingram
Jan 3 at 21:35
@DustinIngram I don't have any of them as I'm trying to contruct them within my app itself. But maybe it's impossible. For what I understand the .mo file created by the write_mo() function is just cached but not saved anywere that's why I think the added code doesn't work but I don't know how to save it.
– Paolo177
Jan 3 at 21:44