def gettargetlanguage(self): """Return the target language based on information in the header. The target language is determined in the following sequence: 1. Use the 'Language' entry in the header. 2. Poedit's custom headers. 3. Analysing the 'Language-Team' entry. """ header = self.parseheader() lang = header.get('Language', None) if lang is not None: from translate.lang.data import langcode_ire if langcode_ire.match(lang): return lang else: lang = None if 'X-Poedit-Language' in header: from translate.lang import poedit language = header.get('X-Poedit-Language') country = header.get('X-Poedit-Country') return poedit.isocode(language, country) if 'Language-Code' in header: # Used in Plone files return header.get('Language-Code') if 'Language-Team' in header: from translate.lang.team import guess_language return guess_language(header.get('Language-Team')) return None
def gettargetlanguage(self): """Return the target language if specified in the header. Some attempt at understanding Poedit's custom headers is done.""" header = self.parseheader() if 'X-Poedit-Language' in header: from translate.lang import poedit language = header.get('X-Poedit-Language') country = header.get('X-Poedit-Country') return poedit.isocode(language, country) return header.get('Language')
def test_isocode(): """Test the isocode function""" # Standard lookup assert isocode("French") == "fr" # Dialect lookups: Portuguese assert isocode("Portuguese") == "pt" # No country we default to 'None' assert isocode("Portuguese", "BRAZIL") == "pt_BR" # Country with a valid dialect assert isocode("Portuguese", "PORTUGAL") == "pt" assert isocode("Portuguese", "MOZAMBIQUE") == "pt" # Country is not a dialect so use default # Dialect lookups: English assert isocode("English") == "en" assert isocode("English", "UNITED KINGDOM") == "en_GB" assert isocode("English", "UNITED STATES") == "en"