[IMP] Activate translation when language is not the default one

bzr revid: fme@openerp.com-20130923131301-mjr0tmth2z1qamfa
This commit is contained in:
Fabien Meghazi 2013-09-23 15:13:01 +02:00
parent 5fc4037ae7
commit 4c3afa6078
4 changed files with 45 additions and 35 deletions

View File

@ -35,7 +35,7 @@ PIL_MIME_MAPPING = {'PNG': 'image/png', 'JPEG': 'image/jpeg', 'GIF': 'image/gif'
# Completely arbitrary limits
MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768)
class Website(openerp.addons.web.controllers.main.Home):
@website.route('/', type='http', auth="admin")
@website.route('/', type='http', auth="admin", multilang=True)
def index(self, **kw):
return self.page("website.homepage")

View File

@ -5,36 +5,36 @@
website.templates.push('/website/static/src/xml/website.translator.xml');
website.EditorBar.include({
events: _.extend({}, website.EditorBar.prototype.events, {
'click a[data-action=js_website_translator]': function (ev) {
var self = this;
ev.preventDefault();
if (!localStorage['website_translator_nodialog']) {
var dialog = new website.TranslatorDialog();
dialog.appendTo($(document.body));
dialog.on('activate', this, function () {
dialog.$el.modal('hide');
this.translateMode();
});
} else {
this.translateMode();
}
},
}),
temporaryHack: function() {
// TODO: refactor once xmo's feature branch is merged
debugger
this.$buttons.edit.prop('disabled', true);
start: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
// TODO: refactor once xmo's feature branch is merged
// and make t-field's work as well as text translation
self.$('button[data-action=edit]').text("Translate");
self.$('[data-action=snippet]').hide();
self.$('#customize-menu-button').hide();
});
},
edit: function () {
var self = this;
if (!localStorage['website_translator_nodialog']) {
var dialog = new website.TranslatorDialog();
dialog.appendTo($(document.body));
dialog.on('activate', this, function () {
dialog.$el.modal('hide');
this.translate();
});
} else {
this.translate();
}
},
translate: function () {
var self = this;
// this.edit();
this.$('#website-top-view').hide();
this.$('#website-top-edit').show();
$('.css_non_editable_mode_hidden').removeClass("css_non_editable_mode_hidden");
this.$el.find('[data-action=snippet]').hide();
this.save = this.saveTranslations;
},
translateMode: function () {
var self = this;
this.temporaryHack();
// this.edit(); -- Will need a translation mode
this.translations = null;
openerp.jsonRpc('/website/get_view_translations', 'call', {
'xml_id': $(document.documentElement).data('view-xmlid'),
@ -88,8 +88,9 @@
node.contentEditable = true;
$(node).data('initial_content', node.childNodes[0].data);
},
saveTranslations: function () {
save: function () {
var trans = {};
// this._super.apply(this, arguments);
$('.oe_translatable_text.oe_dirty').each(function () {
var $node = $(this);
var text = $node.text();

View File

@ -22,7 +22,6 @@
<li><a data-action="show-mobile-preview" href="#"><span title="Mobile preview" class="icon-mobile-phone"/></a></li>
<li class="divider-vertical"></li>
<li><a data-action="promote-current-page" href="#"><span title="Promote page on the web">Promote</span></a></li>
<li><a href="#">Translate</a></li>
<li class="dropdown">
<a id="customize-menu-button" class="dropdown-toggle" data-toggle="dropdown" href="#">Customize <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" id="customize-menu">

View File

@ -15,6 +15,7 @@
&lt;!DOCTYPE html&gt;
<html t-att-lang="lang.replace('_', '-')"
t-att-data-editable="'1' if editable else '0'"
t-att-data-translatable="'1' if translatable else '0'"
t-att-data-view-xmlid="str(__stack__[0])">
<head>
<title><t t-esc="title or res_company.name"/></title>
@ -49,11 +50,20 @@
</t>
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.seo.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.snippets.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.ace.js"></script>
<t t-if="editable">
<script type="text/javascript" src="/website/static/src/js/website.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.seo.js"></script>
<t t-if="not translatable">
<script type="text/javascript" src="/website/static/src/js/website.snippets.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.ace.js"></script>
</t>
<t t-if="translatable">
<script type="text/javascript" src="/website/static/src/js/website.translator.js"></script>
</t>
</t>
<t t-raw="head or ''"/>
<t t-call="website.theme"/>