[Add] Language Flag For Website

This commit is contained in:
gaurav_patel123 2018-01-17 14:34:27 +05:30
parent aa7a8326a3
commit a575531420
3 changed files with 30 additions and 0 deletions

View File

@ -335,6 +335,33 @@
</ul>
</template>
<template id="language_flags" name="Language Flags">
<li
t-if="(request and request.is_frontend_multilang and len(languages) &gt; 1) or (website and (editable or translatable))"
class="dropdown language_dropdown">
<a href="#" class="dropdown-toggle language_flag" data-toggle="dropdown">
<t t-foreach="website.language_ids" t-as="lg">
<t t-if="request.context.get('lang') == lg.code">
<img t-att-src="website.image_url(lg, 'lang_flag')" height="30"
width="30" t-att-title="lg.name" />
</t>
</t>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" style="min-width: 80px;">
<li t-foreach="website.language_ids" t-as="lg">
<a
t-att-href="url_for(request.httprequest.path + '?' + keep_query(), lang=lg.code)"
t-att-data-default-lang="(editable or translatable) and 'true' if website and lg.code == website.default_lang_code else None"
t-att-data-lang="lg.code" t-att-data-lang_dir="lg.direction" class="js_change_lang">
<img t-att-src="website.image_url(lg, 'lang_flag')" height="30" width="30" t-att-title="lg.code" />
<t t-esc="lg.name.split('/').pop()"/>
</a>
</li>
</ul>
</li>
</template>
<template id="footer_default" inherit_id="website.footer_custom" customize_show="True" name="Automatic Footer">
<xpath expr="//div[@id='footer']" position="replace" >
<div id="footer" class="container hidden-print" t-if='not no_footer'>

View File

@ -25,6 +25,7 @@ class Lang(models.Model):
_disallowed_datetime_patterns = list(tools.DATETIME_FORMATS_MAP)
_disallowed_datetime_patterns.remove('%y') # this one is in fact allowed, just not good practice
image = fields.Binary(string='Language Flag')
name = fields.Char(required=True)
code = fields.Char(string='Locale Code', required=True, help='This field is used to set/get locales for user')
iso_code = fields.Char(string='ISO code', help='This ISO code is the name of po files to use for translations')

View File

@ -38,6 +38,8 @@
<field name="code"/>
<field name="iso_code"/>
<field name="translatable"/>
<newline />
<field name="image" widget='image'></field>
</group>
<group>
<field name="direction"/>