summaryrefslogtreecommitdiff
path: root/bin/addons/base/module
diff options
context:
space:
mode:
authorYSA (Openerp) <ysa@tinyerp.com>2011-01-20 11:07:33 +0530
committerYSA (Openerp) <ysa@tinyerp.com>2011-01-20 11:07:33 +0530
commitf030d1219e2411e4b557f960d603fca1fcbb012e (patch)
treef7cc7e772563e2a1fecc9713987b569af35bd0d4 /bin/addons/base/module
parent1b287f9b7b7ffc6719a7839753597341cc75d7fb (diff)
parent10a6bb350c2f054e262ee4649855185795e611d5 (diff)
Merge with trunk-server
bzr revid: ysa@tinyerp.com-20110120053733-ws7mfcfw15p0iyy1
Diffstat (limited to 'bin/addons/base/module')
-rw-r--r--bin/addons/base/module/module.py80
-rw-r--r--bin/addons/base/module/wizard/base_export_language.py4
-rw-r--r--bin/addons/base/module/wizard/base_language_install.py14
-rw-r--r--bin/addons/base/module/wizard/base_language_install_view.xml14
-rw-r--r--bin/addons/base/module/wizard/base_module_configuration_view.xml8
-rw-r--r--bin/addons/base/module/wizard/base_module_shortcut_data.xml13
6 files changed, 107 insertions, 26 deletions
diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py
index d050355ab05..2e276433e63 100644
--- a/bin/addons/base/module/module.py
+++ b/bin/addons/base/module/module.py
@@ -19,11 +19,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
+import base64
+import cStringIO
import imp
import logging
import os
import re
+import StringIO
import urllib
+import zipfile
import zipimport
import addons
@@ -554,6 +558,58 @@ class module(osv.osv):
else:
self._web_dependencies(
cr, uid, parent, context=context)
+
+ def _translations_subdir(self, module):
+ """ Returns the path to the subdirectory holding translations for the
+ module files, or None if it can't find one
+
+ :param module: a module object
+ :type module: browse(ir.module.module)
+ """
+ subdir = addons.get_module_resource(module.name, 'po')
+ if subdir: return subdir
+ # old naming convention
+ subdir = addons.get_module_resource(module.name, 'i18n')
+ if subdir: return subdir
+ return None
+
+ def _add_translations(self, module, web_data):
+ """ Adds translation data to a zipped web module
+
+ :param module: a module descriptor
+ :type module: browse(ir.module.module)
+ :param web_data: zipped data of a web module
+ :type web_data: bytes
+ """
+ # cStringIO.StringIO is either read or write, not r/w
+ web_zip = StringIO.StringIO(web_data)
+ web_archive = zipfile.ZipFile(web_zip, 'a')
+
+ # get the contents of the i18n or po folder and move them to the
+ # po/messages subdirectory of the web module.
+ # The POT file will be incorrectly named, but that should not
+ # matter since the web client is not going to use it, only the PO
+ # files.
+ translations_file = cStringIO.StringIO(
+ addons.zip_directory(self._translations_subdir(module), False))
+ translations_archive = zipfile.ZipFile(translations_file)
+
+ for path in translations_archive.namelist():
+ web_path = os.path.join(
+ 'web', 'po', 'messages', os.path.basename(path))
+ web_archive.writestr(
+ web_path,
+ translations_archive.read(path))
+
+ translations_archive.close()
+ translations_file.close()
+
+ web_archive.close()
+ try:
+ return web_zip.getvalue()
+ finally:
+ web_zip.close()
+
def get_web(self, cr, uid, names, context=None):
""" get_web(cr, uid, [module_name], context) -> [{name, depends, content}]
@@ -568,15 +624,21 @@ class module(osv.osv):
if not modules: return []
self.__logger.info('Sending web content of modules %s '
'to web client', names)
- return [
- {'name': module.name,
- 'version': module.installed_version,
- 'depends': list(self._web_dependencies(
- cr, uid, module, context=context)),
- 'content': addons.zip_directory(
- addons.get_module_resource(module.name, 'web'))}
- for module in modules
- ]
+
+ modules_data = []
+ for module in modules:
+ web_data = addons.zip_directory(
+ addons.get_module_resource(module.name, 'web'), False)
+ if self._translations_subdir(module):
+ web_data = self._add_translations(module, web_data)
+ modules_data.append({
+ 'name': module.name,
+ 'version': module.installed_version,
+ 'depends': list(self._web_dependencies(
+ cr, uid, module, context=context)),
+ 'content': base64.encodestring(web_data)
+ })
+ return modules_data
module()
diff --git a/bin/addons/base/module/wizard/base_export_language.py b/bin/addons/base/module/wizard/base_export_language.py
index 1b43b561ac3..86683bbcc4f 100644
--- a/bin/addons/base/module/wizard/base_export_language.py
+++ b/bin/addons/base/module/wizard/base_export_language.py
@@ -47,7 +47,7 @@ class base_language_export(osv.osv_memory):
mods = map(lambda m: m.name, this.modules) or ['all']
mods.sort()
buf=cStringIO.StringIO()
- tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
+ tools.trans_export(this.lang, mods, buf, this.format, cr)
if this.format == 'csv':
this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
elif this.format == 'po':
@@ -86,4 +86,4 @@ class base_language_export(osv.osv_memory):
}
base_language_export()
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/bin/addons/base/module/wizard/base_language_install.py b/bin/addons/base/module/wizard/base_language_install.py
index f7b469f85ed..1e40f84cc60 100644
--- a/bin/addons/base/module/wizard/base_language_install.py
+++ b/bin/addons/base/module/wizard/base_language_install.py
@@ -21,6 +21,7 @@
import tools
from osv import osv, fields
+from tools.translate import _
class base_language_install(osv.osv_memory):
""" Install Language"""
@@ -50,7 +51,18 @@ class base_language_install(osv.osv_memory):
context = {'overwrite': True}
modobj.update_translations(cr, uid, mids, lang, context or {})
self.write(cr, uid, ids, {'state': 'done'}, context=context)
- return False
+ return {
+ 'name': _('Language Pack'),
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'view_id': False,
+ 'res_model': 'base.language.install',
+ 'domain': [],
+ 'context': dict(context, active_ids=ids),
+ 'type': 'ir.actions.act_window',
+ 'target': 'new',
+ 'res_id': ids and ids[0] or False,
+ }
base_language_install()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/bin/addons/base/module/wizard/base_language_install_view.xml b/bin/addons/base/module/wizard/base_language_install_view.xml
index d207ea9ea29..250710e0d37 100644
--- a/bin/addons/base/module/wizard/base_language_install_view.xml
+++ b/bin/addons/base/module/wizard/base_language_install_view.xml
@@ -8,8 +8,8 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Load Official Translation">
- <group col="8">
- <group colspan="3">
+ <group colspan="4" col="8">
+ <group colspan="1">
<field name="config_logo" widget="image" width="220" height="130" nolabel="1" colspan="1"/>
<newline/>
<label colspan="4" width="220" string="This wizard helps you add a new language to your OpenERP system. After loading a new language it becomes available as default interface language for users and partners."/>
@@ -17,8 +17,8 @@
<label colspan="4" width="220" string="Please be patient, this operation may take a few minutes (depending on the number of modules currently installed)..."/>
<field name="state" invisible="1"/>
</group>
- <separator orientation="vertical" rowspan="15"/>
- <group colspan="4">
+ <separator orientation="vertical" colspan="1" rowspan="12"/>
+ <group colspan="6">
<separator string="Load an Official Translation" colspan="4"/>
<group states="init" colspan="4">
<field name="lang" colspan="4"/>
@@ -29,18 +29,18 @@
You must change the preferences of the user and open a new menu to view the changes." colspan="4"/>
</group>
</group>
+ </group>
<group colspan="8" col="8" states="init">
<separator string="" colspan="8"/>
<label colspan="6" width="220"/>
- <button special="cancel" string="Cancel" icon="gtk-cancel"/>
- <button name="lang_install" string="Load" type="object" icon="gtk-ok"/>
+ <button special="cancel" string="Cancel" icon="gtk-cancel" colspan="1"/>
+ <button name="lang_install" string="Load" type="object" icon="gtk-ok" colspan="1"/>
</group>
<group colspan="8" col="8" states="done">
<separator string="" colspan="8"/>
<label colspan="7" width="220"/>
<button special="cancel" string="Close" icon="gtk-ok"/>
</group>
- </group>
</form>
</field>
</record>
diff --git a/bin/addons/base/module/wizard/base_module_configuration_view.xml b/bin/addons/base/module/wizard/base_module_configuration_view.xml
index 8ab47e2c2bc..f8abf1e2732 100644
--- a/bin/addons/base/module/wizard/base_module_configuration_view.xml
+++ b/bin/addons/base/module/wizard/base_module_configuration_view.xml
@@ -24,7 +24,7 @@
<field name="code">action = obj.start()</field>
</record>
- <menuitem name="Start Configuration"
+ <menuitem name="Reconfigure"
action="action_start_configurator"
id="menu_view_base_module_configuration" parent="base.menu_config"
type="server" icon="STOCK_EXECUTE" sequence="100" />
@@ -38,12 +38,6 @@
<field name="key">action</field>
<field name="model">ir.actions.todo</field>
</record>
- <record id="ir_ui_view_sc_configuration" model="ir.ui.view_sc">
- <field name="name">Reconfigure</field>
- <field name="resource">ir.ui.menu</field>
- <field name="user_id" ref="base.user_root"/>
- <field name="res_id" ref="menu_view_base_module_configuration"/>
- </record>
</data>
</openerp>
diff --git a/bin/addons/base/module/wizard/base_module_shortcut_data.xml b/bin/addons/base/module/wizard/base_module_shortcut_data.xml
new file mode 100644
index 00000000000..e5faaabdd5e
--- /dev/null
+++ b/bin/addons/base/module/wizard/base_module_shortcut_data.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data noupdate="1">
+
+ <record id="ir_ui_view_sc_configuration" model="ir.ui.view_sc">
+ <field name="name">Reconfigure</field>
+ <field name="resource">ir.ui.menu</field>
+ <field name="user_id" ref="base.user_root"/>
+ <field name="res_id" ref="menu_view_base_module_configuration"/>
+ </record>
+
+ </data>
+</openerp>