From bd95f542addb4b1abb121bf5c38c2eafce336343 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 11 Aug 2011 18:39:33 +0200 Subject: [PATCH] [imp] setup i18n bzr revid: nicolas.vanhoren@openerp.com-20110811163933-lcs6zv2e3kn8b09j --- addons/base/controllers/main.py | 16 +++++++++++++ addons/base/po/base.pot | 23 ++++++++++++++++++ addons/base/po/fr.po | 23 ++++++++++++++++++ babel.cfg | 13 +++++++++++ gen_translations.sh | 41 +++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 addons/base/po/base.pot create mode 100644 addons/base/po/fr.po create mode 100644 babel.cfg create mode 100755 gen_translations.sh diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index aaf89853cad..155c50a449a 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -18,6 +18,7 @@ import openerpweb import openerpweb.ast import openerpweb.nonliterals +from babel.messages.pofile import read_po # Should move to openerpweb.Xml2Json class Xml2Json: @@ -156,6 +157,21 @@ class WebClient(openerpweb.Controller): 'css': css } return r + + @openerpweb.jsonrequest + def translations(self, addon_name, lang): + f_name = os.path.join(openerpweb.path_addons, addon_name, "po", lang + ".po") + with open(f_name) as t_file: + po = read_po(t_file) + + transl = {"messages":[]} + + for x in po: + if x.id: + transl["messages"].append({'id': x.id, 'string': x.string}) + + return transl + class Database(openerpweb.Controller): _cp_path = "/base/database" diff --git a/addons/base/po/base.pot b/addons/base/po/base.pot new file mode 100644 index 00000000000..1609924cac3 --- /dev/null +++ b/addons/base/po/base.pot @@ -0,0 +1,23 @@ +# Translations template for PROJECT. +# Copyright (C) 2011 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2011. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2011-08-09 17:30+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.4\n" + +#: addons/base/static/src/js/core.js:11 +msgid "I am a sweet chicken." +msgstr "" + diff --git a/addons/base/po/fr.po b/addons/base/po/fr.po new file mode 100644 index 00000000000..c1483c0e9ca --- /dev/null +++ b/addons/base/po/fr.po @@ -0,0 +1,23 @@ +# Translations template for PROJECT. +# Copyright (C) 2011 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# niv , 2011. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2011-08-09 17:30+0200\n" +"PO-Revision-Date: 2011-08-09 17:31+0200\n" +"Last-Translator: niv \n" +"Language-Team: French\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.4\n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: addons/base/static/src/js/core.js:11 +msgid "I am a sweet chicken." +msgstr "Je suis un gentil poulet." diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 00000000000..bcfd3572f3e --- /dev/null +++ b/babel.cfg @@ -0,0 +1,13 @@ +## Extraction from Python source files +#[python: **.py] +## Extraction from Genshi HTML and text templates +#[genshi: **/templates/**.html] +#ignore_tags = script,style +#include_attrs = alt title summary +#[genshi: **/templates/**.txt] +#template_class = genshi.template:TextTemplate +#encoding = ISO-8819-15 +## Extraction from JavaScript files +[javascript: **.js] +[javascript: **.xml] + diff --git a/gen_translations.sh b/gen_translations.sh new file mode 100755 index 00000000000..9c3a14e2dcc --- /dev/null +++ b/gen_translations.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +usage() +{ +cat << EOF +usage: $0 -a +usage: $0 DIR OUTPUT_FILE + +OPTIONS: + -a recreate the .pot file for all addons + -h print this message +EOF +exit 0 +} + +do_all= + +while getopts "a" opt +do + case "$opt" in + a) + do_all=true;; + h) + usage;; + \?) + usage;; + esac +done + +shift $((OPTIND-1)) + +if [ -n "$do_all" ] +then + echo "Extracting all the translations" + $0 addons/base/static/src/ addons/base/po/base.pot +elif [ -n "$2" ] +then + pybabel extract -F babel.cfg -o $2 -k _t --no-default-keywords $1 +else + usage +fi