'Create the given language if necessary, and make it active.'

@api.model
def load_lang(self, lang, lang_name=None):

    language = self.with_context(active_test=False).search([('code', '=', lang)], limit=1)
    if language:
        language.write({'active': True})
        return language.id
    fail = True
    iso_lang = tools.get_iso_codes(lang)
    for ln in tools.get_locales(lang):
        try:
            locale.setlocale(locale.LC_ALL, str(ln))
            fail = False
            break
        except locale.Error:
            continue
    if fail:
        lc = locale.getdefaultlocale()[0]
        msg = 'Unable    to    get    information    for    locale    %s.    Information    from    the    default    locale    (%s)    have    been    used.'
        _logger.warning(msg, lang, lc)
    if (not lang_name):
        lang_name = lang
    def fix_xa0(s):
        'Fix    badly-encoded    non-breaking    space    Unicode    character    from    locale.localeconv(),\n                                                            coercing    to    utf-8,    as    some    platform    seem    to    output    localeconv()    in    their    system\n                                                            encoding,    e.g.    Windows-1252'
        if (s == '\xa0'):
            return '\xc2\xa0'
        return s
    def fix_datetime_format(format):
        "Python's    strftime    supports    only    the    format    directives\n                                                            that    are    available    on    the    platform's    libc,    so    in    order    to\n                                                            be    100%    cross-platform    we    map    to    the    directives    required    by\n                                                            the    C    standard    (1989    version),    always    available    on    platforms\n                                                            with    a    C    standard    implementation."
        format = format.replace('%-', '%')
        for (pattern, replacement) in tools.DATETIME_FORMATS_MAP.iteritems():
            format = format.replace(pattern, replacement)
        return str(format)
    conv = locale.localeconv()
    lang_info = {'code': lang, 'iso_code': iso_lang, 'name': lang_name, 'active': True, 'translatable': True, 'date_format': fix_datetime_format(locale.nl_langinfo(locale.D_FMT)), 'time_format': fix_datetime_format(locale.nl_langinfo(locale.T_FMT)), 'decimal_point': fix_xa0(str(conv['decimal_point'])), 'thousands_sep': fix_xa0(str(conv['thousands_sep'])), 'grouping': str(conv.get('grouping', []))}
    try:
        return self.create(lang_info).id
    finally:
        tools.resetlocale()
