[google-appengine] Re: Gettext and GAE/jijas2 integration
Hi. I am the founder of the Worldwide Lexicon project. One of the tools we work on is a simple localization tool called SLS. We're using a version of this in our app to localize UI prompts. What we have now is pretty crude, but it works. We'll be releasing it for GAE when we have had time to finish the admin tools. It works somewhat like gettext but is actually even more convenient. You make a call like s.g(token_name,default_text), and it does the following: 1. check local memory to see if translations have already been loaded (e.g. method has been called several times in same session) 2. loads translations from memcache 3. memcache miss, loads from datastore 4. nothing in datastore, calls a machine translation service (wrote hooks to several), to get a placeholder translation 5. if all of that fails, returns the default_text This makes it easy to prototype an app, because as you add method calls, it learns what you need to localize and fetches machine translations as a starting point. You will obviously want to replace these, but you can see what your app will look like in another language (and if you pick phrases carefully, it will be usable even with machine translations). I'll post a message when we have this in final form. We're busy on some other issues now, but will return to this in a few weeks. Brian McC On Mar 5, 4:54 am, Jose Ramon Palanco wrote: > I will try all posibilities.. If I finally get it working i will > document the process. > > Thanks > > On Thu, Mar 5, 2009 at 1:40 PM, Jarek Zgoda wrote: > > > Also, the gettext docs say it should be "localedir/language/ > > LC_MESSAGES/domain.mo" (ROOT/locale/en_US/LC_MESSAGES/myproject.po - > > following your terminology and layout), not "localedir/LC_MESSAGES/ > > language/domain.mo". > > > On 5 Mar, 13:32, Jarek Zgoda wrote: > >> Shouldn't the "dirname" from your code contain the path where actual > >> catalogs are stored, iow. os.path.join(os.path.dirname(__file__), > >> 'locale')? > > >> On 5 Mar, 13:11, Jose Ramon Palanco wrote: > > >> > So, which one is the best (and easiest) way to build an appengine > >> > project with i18n support without django? I think I will write a dirty > >> > implementation if therer are not solution to solve this problem. > > >> > On Thu, Mar 5, 2009 at 9:09 AM, Jarek Zgoda > >> > wrote: > > >> > > I tried to put Environment object in memcache, but it's not picklable > >> > > so no joy. FileSystemLoader can be pickled and cached, but for some > >> > > unknown reason cached object throws IOErrors if template code changes > >> > > (eg. because of new deployment) and I did not found a way to remove it > >> > > from cache after succesful deployment (and do not have key versioning > >> > > yet). > > >> > > I ended up creating module-level environment object and hoping the > >> > > module will be kept in module cache fo long enough to be reused. > > >> > > On 5 Mar, 01:14, pedepy wrote: > >> > >> just as a side note, loading a jinja2 environment can be quite > >> > >> expensive. You'll wanna seperate this code (that you will no doubt > >> > >> reuse extensively) into it's own method. A little memcache love also > >> > >> wouldnt hurt. > > >> > >> On Mar 4, 7:45 am, Jose wrote: > > >> > >> > I'm new in python and app engine. I'm developing a simple project > >> > >> > without django, just webapp. Instead use django template system I'm > >> > >> > using jijas2. > > >> > >> > To enable jijas2 into my project I downloaded the last version and > >> > >> > after unpack it, I copied jijas2 folder into my project. I added > >> > >> > this > >> > >> > imports: > > >> > >> > from jinja2 import Template > >> > >> > from jinja2 import FileSystemLoader, Environment > > >> > >> > An in my request handler I use templates in this way: > > >> > >> > template_dirs = os.path.join(os.path.dirname(__file__), > >> > >> > 'templates') > >> > >> > env = Environment(loader=FileSystemLoader(template_dirs)) > >> > >> > template = env.get_template("index.html") > >> > >> > rendered = template.render(template_values) > >> > >> > self.response.out.write(rendered) > > >> > >> > Everything works fine. Now, I'm trying to make use of i18n support > >> > >> > in > >> > >> > jijas2. But I have a lot of problems and I would apreciate your > >> > >> > help. > > >> > >> > First of all I read jijas2 documentation and API, and the way to > >> > >> > implement this feature is with this lines: > > >> > >> > import gettext > > >> > >> > (..and in my request handler) > > >> > >> > domain = "myproject" > >> > >> > dirname = os.path.dirname(__file__) > >> > >> > locales = "en_US" > > >> > >> > translations = gettext.find(domain, dirname, locales) > >> > >> > env = Environment(loader=FileSystemLoader > >> > >> > (template_dirs),extensions=['jinja2.ext.i18n']) > >> > >> > env.install_gettext_translations(translations) > > >> > >> > Second question: > > >> > >> > I have experiencie with PHP, so it not s
[google-appengine] Re: Gettext and GAE/jijas2 integration
I will try all posibilities.. If I finally get it working i will document the process. Thanks On Thu, Mar 5, 2009 at 1:40 PM, Jarek Zgoda wrote: > > Also, the gettext docs say it should be "localedir/language/ > LC_MESSAGES/domain.mo" (ROOT/locale/en_US/LC_MESSAGES/myproject.po - > following your terminology and layout), not "localedir/LC_MESSAGES/ > language/domain.mo". > > On 5 Mar, 13:32, Jarek Zgoda wrote: >> Shouldn't the "dirname" from your code contain the path where actual >> catalogs are stored, iow. os.path.join(os.path.dirname(__file__), >> 'locale')? >> >> On 5 Mar, 13:11, Jose Ramon Palanco wrote: >> >> > So, which one is the best (and easiest) way to build an appengine >> > project with i18n support without django? I think I will write a dirty >> > implementation if therer are not solution to solve this problem. >> >> > On Thu, Mar 5, 2009 at 9:09 AM, Jarek Zgoda wrote: >> >> > > I tried to put Environment object in memcache, but it's not picklable >> > > so no joy. FileSystemLoader can be pickled and cached, but for some >> > > unknown reason cached object throws IOErrors if template code changes >> > > (eg. because of new deployment) and I did not found a way to remove it >> > > from cache after succesful deployment (and do not have key versioning >> > > yet). >> >> > > I ended up creating module-level environment object and hoping the >> > > module will be kept in module cache fo long enough to be reused. >> >> > > On 5 Mar, 01:14, pedepy wrote: >> > >> just as a side note, loading a jinja2 environment can be quite >> > >> expensive. You'll wanna seperate this code (that you will no doubt >> > >> reuse extensively) into it's own method. A little memcache love also >> > >> wouldnt hurt. >> >> > >> On Mar 4, 7:45 am, Jose wrote: >> >> > >> > I'm new in python and app engine. I'm developing a simple project >> > >> > without django, just webapp. Instead use django template system I'm >> > >> > using jijas2. >> >> > >> > To enable jijas2 into my project I downloaded the last version and >> > >> > after unpack it, I copied jijas2 folder into my project. I added this >> > >> > imports: >> >> > >> > from jinja2 import Template >> > >> > from jinja2 import FileSystemLoader, Environment >> >> > >> > An in my request handler I use templates in this way: >> >> > >> > template_dirs = os.path.join(os.path.dirname(__file__), >> > >> > 'templates') >> > >> > env = Environment(loader=FileSystemLoader(template_dirs)) >> > >> > template = env.get_template("index.html") >> > >> > rendered = template.render(template_values) >> > >> > self.response.out.write(rendered) >> >> > >> > Everything works fine. Now, I'm trying to make use of i18n support in >> > >> > jijas2. But I have a lot of problems and I would apreciate your help. >> >> > >> > First of all I read jijas2 documentation and API, and the way to >> > >> > implement this feature is with this lines: >> >> > >> > import gettext >> >> > >> > (..and in my request handler) >> >> > >> > domain = "myproject" >> > >> > dirname = os.path.dirname(__file__) >> > >> > locales = "en_US" >> >> > >> > translations = gettext.find(domain, dirname, locales) >> > >> > env = Environment(loader=FileSystemLoader >> > >> > (template_dirs),extensions=['jinja2.ext.i18n']) >> > >> > env.install_gettext_translations(translations) >> >> > >> > Second question: >> >> > >> > I have experiencie with PHP, so it not so hard understand gettext and >> > >> > po/mo files operation, so I think I have to upload my po files into >> > >> > ROOT/locale/LC_MESSAGES/en_US/myproject.po >> >> > >> > Regards > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Gettext and GAE/jijas2 integration
Also, the gettext docs say it should be "localedir/language/ LC_MESSAGES/domain.mo" (ROOT/locale/en_US/LC_MESSAGES/myproject.po - following your terminology and layout), not "localedir/LC_MESSAGES/ language/domain.mo". On 5 Mar, 13:32, Jarek Zgoda wrote: > Shouldn't the "dirname" from your code contain the path where actual > catalogs are stored, iow. os.path.join(os.path.dirname(__file__), > 'locale')? > > On 5 Mar, 13:11, Jose Ramon Palanco wrote: > > > So, which one is the best (and easiest) way to build an appengine > > project with i18n support without django? I think I will write a dirty > > implementation if therer are not solution to solve this problem. > > > On Thu, Mar 5, 2009 at 9:09 AM, Jarek Zgoda wrote: > > > > I tried to put Environment object in memcache, but it's not picklable > > > so no joy. FileSystemLoader can be pickled and cached, but for some > > > unknown reason cached object throws IOErrors if template code changes > > > (eg. because of new deployment) and I did not found a way to remove it > > > from cache after succesful deployment (and do not have key versioning > > > yet). > > > > I ended up creating module-level environment object and hoping the > > > module will be kept in module cache fo long enough to be reused. > > > > On 5 Mar, 01:14, pedepy wrote: > > >> just as a side note, loading a jinja2 environment can be quite > > >> expensive. You'll wanna seperate this code (that you will no doubt > > >> reuse extensively) into it's own method. A little memcache love also > > >> wouldnt hurt. > > > >> On Mar 4, 7:45 am, Jose wrote: > > > >> > I'm new in python and app engine. I'm developing a simple project > > >> > without django, just webapp. Instead use django template system I'm > > >> > using jijas2. > > > >> > To enable jijas2 into my project I downloaded the last version and > > >> > after unpack it, I copied jijas2 folder into my project. I added this > > >> > imports: > > > >> > from jinja2 import Template > > >> > from jinja2 import FileSystemLoader, Environment > > > >> > An in my request handler I use templates in this way: > > > >> > template_dirs = os.path.join(os.path.dirname(__file__), > > >> > 'templates') > > >> > env = Environment(loader=FileSystemLoader(template_dirs)) > > >> > template = env.get_template("index.html") > > >> > rendered = template.render(template_values) > > >> > self.response.out.write(rendered) > > > >> > Everything works fine. Now, I'm trying to make use of i18n support in > > >> > jijas2. But I have a lot of problems and I would apreciate your help. > > > >> > First of all I read jijas2 documentation and API, and the way to > > >> > implement this feature is with this lines: > > > >> > import gettext > > > >> > (..and in my request handler) > > > >> > domain = "myproject" > > >> > dirname = os.path.dirname(__file__) > > >> > locales = "en_US" > > > >> > translations = gettext.find(domain, dirname, locales) > > >> > env = Environment(loader=FileSystemLoader > > >> > (template_dirs),extensions=['jinja2.ext.i18n']) > > >> > env.install_gettext_translations(translations) > > > >> > Second question: > > > >> > I have experiencie with PHP, so it not so hard understand gettext and > > >> > po/mo files operation, so I think I have to upload my po files into > > >> > ROOT/locale/LC_MESSAGES/en_US/myproject.po > > > >> > Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Gettext and GAE/jijas2 integration
Shouldn't the "dirname" from your code contain the path where actual catalogs are stored, iow. os.path.join(os.path.dirname(__file__), 'locale')? On 5 Mar, 13:11, Jose Ramon Palanco wrote: > So, which one is the best (and easiest) way to build an appengine > project with i18n support without django? I think I will write a dirty > implementation if therer are not solution to solve this problem. > > On Thu, Mar 5, 2009 at 9:09 AM, Jarek Zgoda wrote: > > > I tried to put Environment object in memcache, but it's not picklable > > so no joy. FileSystemLoader can be pickled and cached, but for some > > unknown reason cached object throws IOErrors if template code changes > > (eg. because of new deployment) and I did not found a way to remove it > > from cache after succesful deployment (and do not have key versioning > > yet). > > > I ended up creating module-level environment object and hoping the > > module will be kept in module cache fo long enough to be reused. > > > On 5 Mar, 01:14, pedepy wrote: > >> just as a side note, loading a jinja2 environment can be quite > >> expensive. You'll wanna seperate this code (that you will no doubt > >> reuse extensively) into it's own method. A little memcache love also > >> wouldnt hurt. > > >> On Mar 4, 7:45 am, Jose wrote: > > >> > I'm new in python and app engine. I'm developing a simple project > >> > without django, just webapp. Instead use django template system I'm > >> > using jijas2. > > >> > To enable jijas2 into my project I downloaded the last version and > >> > after unpack it, I copied jijas2 folder into my project. I added this > >> > imports: > > >> > from jinja2 import Template > >> > from jinja2 import FileSystemLoader, Environment > > >> > An in my request handler I use templates in this way: > > >> > template_dirs = os.path.join(os.path.dirname(__file__), > >> > 'templates') > >> > env = Environment(loader=FileSystemLoader(template_dirs)) > >> > template = env.get_template("index.html") > >> > rendered = template.render(template_values) > >> > self.response.out.write(rendered) > > >> > Everything works fine. Now, I'm trying to make use of i18n support in > >> > jijas2. But I have a lot of problems and I would apreciate your help. > > >> > First of all I read jijas2 documentation and API, and the way to > >> > implement this feature is with this lines: > > >> > import gettext > > >> > (..and in my request handler) > > >> > domain = "myproject" > >> > dirname = os.path.dirname(__file__) > >> > locales = "en_US" > > >> > translations = gettext.find(domain, dirname, locales) > >> > env = Environment(loader=FileSystemLoader > >> > (template_dirs),extensions=['jinja2.ext.i18n']) > >> > env.install_gettext_translations(translations) > > >> > Second question: > > >> > I have experiencie with PHP, so it not so hard understand gettext and > >> > po/mo files operation, so I think I have to upload my po files into > >> > ROOT/locale/LC_MESSAGES/en_US/myproject.po > > >> > Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Gettext and GAE/jijas2 integration
So, which one is the best (and easiest) way to build an appengine project with i18n support without django? I think I will write a dirty implementation if therer are not solution to solve this problem. On Thu, Mar 5, 2009 at 9:09 AM, Jarek Zgoda wrote: > > I tried to put Environment object in memcache, but it's not picklable > so no joy. FileSystemLoader can be pickled and cached, but for some > unknown reason cached object throws IOErrors if template code changes > (eg. because of new deployment) and I did not found a way to remove it > from cache after succesful deployment (and do not have key versioning > yet). > > I ended up creating module-level environment object and hoping the > module will be kept in module cache fo long enough to be reused. > > On 5 Mar, 01:14, pedepy wrote: >> just as a side note, loading a jinja2 environment can be quite >> expensive. You'll wanna seperate this code (that you will no doubt >> reuse extensively) into it's own method. A little memcache love also >> wouldnt hurt. >> >> On Mar 4, 7:45 am, Jose wrote: >> >> > I'm new in python and app engine. I'm developing a simple project >> > without django, just webapp. Instead use django template system I'm >> > using jijas2. >> >> > To enable jijas2 into my project I downloaded the last version and >> > after unpack it, I copied jijas2 folder into my project. I added this >> > imports: >> >> > from jinja2 import Template >> > from jinja2 import FileSystemLoader, Environment >> >> > An in my request handler I use templates in this way: >> >> > template_dirs = os.path.join(os.path.dirname(__file__), >> > 'templates') >> > env = Environment(loader=FileSystemLoader(template_dirs)) >> > template = env.get_template("index.html") >> > rendered = template.render(template_values) >> > self.response.out.write(rendered) >> >> > Everything works fine. Now, I'm trying to make use of i18n support in >> > jijas2. But I have a lot of problems and I would apreciate your help. >> >> > First of all I read jijas2 documentation and API, and the way to >> > implement this feature is with this lines: >> >> > import gettext >> >> > (..and in my request handler) >> >> > domain = "myproject" >> > dirname = os.path.dirname(__file__) >> > locales = "en_US" >> >> > translations = gettext.find(domain, dirname, locales) >> > env = Environment(loader=FileSystemLoader >> > (template_dirs),extensions=['jinja2.ext.i18n']) >> > env.install_gettext_translations(translations) >> >> > Second question: >> >> > I have experiencie with PHP, so it not so hard understand gettext and >> > po/mo files operation, so I think I have to upload my po files into >> > ROOT/locale/LC_MESSAGES/en_US/myproject.po >> >> > Regards > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Gettext and GAE/jijas2 integration
I tried to put Environment object in memcache, but it's not picklable so no joy. FileSystemLoader can be pickled and cached, but for some unknown reason cached object throws IOErrors if template code changes (eg. because of new deployment) and I did not found a way to remove it from cache after succesful deployment (and do not have key versioning yet). I ended up creating module-level environment object and hoping the module will be kept in module cache fo long enough to be reused. On 5 Mar, 01:14, pedepy wrote: > just as a side note, loading a jinja2 environment can be quite > expensive. You'll wanna seperate this code (that you will no doubt > reuse extensively) into it's own method. A little memcache love also > wouldnt hurt. > > On Mar 4, 7:45 am, Jose wrote: > > > I'm new in python and app engine. I'm developing a simple project > > without django, just webapp. Instead use django template system I'm > > using jijas2. > > > To enable jijas2 into my project I downloaded the last version and > > after unpack it, I copied jijas2 folder into my project. I added this > > imports: > > > from jinja2 import Template > > from jinja2 import FileSystemLoader, Environment > > > An in my request handler I use templates in this way: > > > template_dirs = os.path.join(os.path.dirname(__file__), > > 'templates') > > env = Environment(loader=FileSystemLoader(template_dirs)) > > template = env.get_template("index.html") > > rendered = template.render(template_values) > > self.response.out.write(rendered) > > > Everything works fine. Now, I'm trying to make use of i18n support in > > jijas2. But I have a lot of problems and I would apreciate your help. > > > First of all I read jijas2 documentation and API, and the way to > > implement this feature is with this lines: > > > import gettext > > > (..and in my request handler) > > > domain = "myproject" > > dirname = os.path.dirname(__file__) > > locales = "en_US" > > > translations = gettext.find(domain, dirname, locales) > > env = Environment(loader=FileSystemLoader > > (template_dirs),extensions=['jinja2.ext.i18n']) > > env.install_gettext_translations(translations) > > > Second question: > > > I have experiencie with PHP, so it not so hard understand gettext and > > po/mo files operation, so I think I have to upload my po files into > > ROOT/locale/LC_MESSAGES/en_US/myproject.po > > > Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Gettext and GAE/jijas2 integration
just as a side note, loading a jinja2 environment can be quite expensive. You'll wanna seperate this code (that you will no doubt reuse extensively) into it's own method. A little memcache love also wouldnt hurt. On Mar 4, 7:45 am, Jose wrote: > I'm new in python and app engine. I'm developing a simple project > without django, just webapp. Instead use django template system I'm > using jijas2. > > To enable jijas2 into my project I downloaded the last version and > after unpack it, I copied jijas2 folder into my project. I added this > imports: > > from jinja2 import Template > from jinja2 import FileSystemLoader, Environment > > An in my request handler I use templates in this way: > > template_dirs = os.path.join(os.path.dirname(__file__), > 'templates') > env = Environment(loader=FileSystemLoader(template_dirs)) > template = env.get_template("index.html") > rendered = template.render(template_values) > self.response.out.write(rendered) > > Everything works fine. Now, I'm trying to make use of i18n support in > jijas2. But I have a lot of problems and I would apreciate your help. > > First of all I read jijas2 documentation and API, and the way to > implement this feature is with this lines: > > import gettext > > (..and in my request handler) > > domain = "myproject" > dirname = os.path.dirname(__file__) > locales = "en_US" > > translations = gettext.find(domain, dirname, locales) > env = Environment(loader=FileSystemLoader > (template_dirs),extensions=['jinja2.ext.i18n']) > env.install_gettext_translations(translations) > > Second question: > > I have experiencie with PHP, so it not so hard understand gettext and > po/mo files operation, so I think I have to upload my po files into > ROOT/locale/LC_MESSAGES/en_US/myproject.po > > Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---