Ticket #4030: 4030_language_info_v2_r8347_updated_languages.diff
File 4030_language_info_v2_r8347_updated_languages.diff, 20.2 KB (added by , 16 years ago) |
---|
-
django/conf/language_info.py
1 # This file was generated with django/bin/make-language-info.py and it is not 2 # recommended to edit it by hand. For new translations, compile the new .po 3 # files and edit the LANGUAGES setting, and finally re-run 4 # django/bin/make-language-info.py to generate this file. 5 6 language_info = { 7 'ar': {'bidi': True, 8 'language_code': 'ar', 9 'name': 'Arabic', 10 'name_local': u'Arabic'}, 11 'bg': {'bidi': False, 12 'language_code': 'bg', 13 'name': 'Bulgarian', 14 'name_local': u'\u0431\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438'}, 15 'bn': {'bidi': False, 16 'language_code': 'bn', 17 'name': 'Bengali', 18 'name_local': u'\u09ac\u09be\u0982\u09b2\u09be'}, 19 'ca': {'bidi': False, 20 'language_code': 'ca', 21 'name': 'Catalan', 22 'name_local': u'catal\xe0'}, 23 'cs': {'bidi': False, 24 'language_code': 'cs', 25 'name': 'Czech', 26 'name_local': u'\u010desky'}, 27 'cy': {'bidi': False, 28 'language_code': 'cy', 29 'name': 'Welsh', 30 'name_local': u'Cymraeg'}, 31 'da': {'bidi': False, 32 'language_code': 'da', 33 'name': 'Danish', 34 'name_local': u'Dansk'}, 35 'de': {'bidi': False, 36 'language_code': 'de', 37 'name': 'German', 38 'name_local': u'Deutsch'}, 39 'el': {'bidi': False, 40 'language_code': 'el', 41 'name': 'Greek', 42 'name_local': u'\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac'}, 43 'en': {'bidi': False, 44 'language_code': 'en', 45 'name': 'English', 46 'name_local': u'English'}, 47 'es': {'bidi': False, 48 'language_code': 'es', 49 'name': 'Spanish', 50 'name_local': u'espa\xf1ol'}, 51 'es-ar': {'bidi': False, 52 'language_code': 'es-ar', 53 'name': 'Argentinean Spanish', 54 'name_local': u'espa\xf1ol de Argentina'}, 55 'et': {'bidi': False, 56 'language_code': 'et', 57 'name': 'Estonian', 58 'name_local': u'Estonian'}, 59 'eu': {'bidi': False, 60 'language_code': 'eu', 61 'name': 'Basque', 62 'name_local': u'Basque'}, 63 'fa': {'bidi': True, 64 'language_code': 'fa', 65 'name': 'Persian', 66 'name_local': u'Persian'}, 67 'fi': {'bidi': False, 68 'language_code': 'fi', 69 'name': 'Finnish', 70 'name_local': u'suomi'}, 71 'fr': {'bidi': False, 72 'language_code': 'fr', 73 'name': 'French', 74 'name_local': u'Fran\xe7ais'}, 75 'ga': {'bidi': False, 76 'language_code': 'ga', 77 'name': 'Irish', 78 'name_local': u'Gaeilge'}, 79 'gl': {'bidi': False, 80 'language_code': 'gl', 81 'name': 'Galician', 82 'name_local': u'galego'}, 83 'he': {'bidi': True, 84 'language_code': 'he', 85 'name': 'Hebrew', 86 'name_local': u'\u05e2\u05d1\u05e8\u05d9\u05ea'}, 87 'hr': {'bidi': False, 88 'language_code': 'hr', 89 'name': 'Croatian', 90 'name_local': u'Hrvatski'}, 91 'hu': {'bidi': False, 92 'language_code': 'hu', 93 'name': 'Hungarian', 94 'name_local': u'Magyar'}, 95 'is': {'bidi': False, 96 'language_code': 'is', 97 'name': 'Icelandic', 98 'name_local': u'\xcdslenska'}, 99 'it': {'bidi': False, 100 'language_code': 'it', 101 'name': 'Italian', 102 'name_local': u'Italiano'}, 103 'ja': {'bidi': False, 104 'language_code': 'ja', 105 'name': 'Japanese', 106 'name_local': u'\u65e5\u672c\u8a9e'}, 107 'ka': {'bidi': False, 108 'language_code': 'ka', 109 'name': 'Georgian', 110 'name_local': u'\u10e5\u10d0\u10e0\u10d7\u10e3\u10da\u10d8'}, 111 'km': {'bidi': False, 112 'language_code': 'km', 113 'name': 'Khmer', 114 'name_local': u'Khmer'}, 115 'kn': {'bidi': False, 116 'language_code': 'kn', 117 'name': 'Kannada', 118 'name_local': u'Kannada'}, 119 'ko': {'bidi': False, 120 'language_code': 'ko', 121 'name': 'Korean', 122 'name_local': u'\ud55c\uad6d\uc5b4'}, 123 'lt': {'bidi': False, 124 'language_code': 'lt', 125 'name': 'Lithuanian', 126 'name_local': u'Lithuanian'}, 127 'lv': {'bidi': False, 128 'language_code': 'lv', 129 'name': 'Latvian', 130 'name_local': u'Latvie\u0161u'}, 131 'mk': {'bidi': False, 132 'language_code': 'mk', 133 'name': 'Macedonian', 134 'name_local': u'\u041c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0438'}, 135 'nl': {'bidi': False, 136 'language_code': 'nl', 137 'name': 'Dutch', 138 'name_local': u'Nederlands'}, 139 'no': {'bidi': False, 140 'language_code': 'no', 141 'name': 'Norwegian', 142 'name_local': u'Norsk'}, 143 'pl': {'bidi': False, 144 'language_code': 'pl', 145 'name': 'Polish', 146 'name_local': u'Polski'}, 147 'pt': {'bidi': False, 148 'language_code': 'pt', 149 'name': 'Portugese', 150 'name_local': u'Portugese'}, 151 'pt-br': {'bidi': False, 152 'language_code': 'pt-br', 153 'name': 'Brazilian Portuguese', 154 'name_local': u'Portugu\xeas Brasileiro'}, 155 'ro': {'bidi': False, 156 'language_code': 'ro', 157 'name': 'Romanian', 158 'name_local': u'Romana'}, 159 'ru': {'bidi': False, 160 'language_code': 'ru', 161 'name': 'Russian', 162 'name_local': u'\u0420\u0443\u0441\u0441\u043a\u0438\u0439'}, 163 'sk': {'bidi': False, 164 'language_code': 'sk', 165 'name': 'Slovak', 166 'name_local': u'Slovensky'}, 167 'sl': {'bidi': False, 168 'language_code': 'sl', 169 'name': 'Slovenian', 170 'name_local': u'Slovenski'}, 171 'sr': {'bidi': False, 172 'language_code': 'sr', 173 'name': 'Serbian', 174 'name_local': u'Srpski'}, 175 'sv': {'bidi': False, 176 'language_code': 'sv', 177 'name': 'Swedish', 178 'name_local': u'Svenska'}, 179 'ta': {'bidi': False, 180 'language_code': 'ta', 181 'name': 'Tamil', 182 'name_local': u'\u0ba4\u0bae\u0bbf\u0bb4\u0bcd'}, 183 'te': {'bidi': False, 184 'language_code': 'te', 185 'name': 'Telugu', 186 'name_local': u'Telugu'}, 187 'tr': {'bidi': False, 188 'language_code': 'tr', 189 'name': 'Turkish', 190 'name_local': u'T\xfcrk\xe7e'}, 191 'uk': {'bidi': False, 192 'language_code': 'uk', 193 'name': 'Ukrainian', 194 'name_local': u'Ukrainian'}, 195 'zh-cn': {'bidi': False, 196 'language_code': 'zh-cn', 197 'name': 'Simplified Chinese', 198 'name_local': u'\u7b80\u4f53\u4e2d\u6587'}, 199 'zh-tw': {'bidi': False, 200 'language_code': 'zh-tw', 201 'name': 'Traditional Chinese', 202 'name_local': u'\u7e41\u9ad4\u4e2d\u6587'} 203 } -
django/templatetags/i18n.py
17 17 context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES] 18 18 return '' 19 19 20 class GetLanguageInfoNode(Node): 21 def __init__(self, lang_code, variable): 22 self.lang_code = Variable(lang_code) 23 self.variable = variable 24 25 def render(self, context): 26 lang_code = self.lang_code.resolve(context) 27 context[self.variable] = translation.get_language_info(lang_code) 28 return '' 29 30 class GetLanguageInfoListNode(Node): 31 def __init__(self, languages, variable): 32 self.languages = Variable(languages) 33 self.variable = variable 34 35 def get_language_info(self, language): 36 # ``language`` is either a language code string or a sequence with the 37 # language code as its first item 38 if len(language[0]) > 1: 39 return translation.get_language_info(language[0]) 40 else: 41 return translation.get_language_info(str(language)) 42 43 def render(self, context): 44 languages = self.languages.resolve(context) 45 context[self.variable] = [self.get_language_info(l) for l in languages] 46 return '' 47 20 48 class GetCurrentLanguageNode(Node): 21 49 def __init__(self, variable): 22 50 self.variable = variable … … 107 135 raise TemplateSyntaxError, "'get_available_languages' requires 'as variable' (got %r)" % args 108 136 return GetAvailableLanguagesNode(args[2]) 109 137 138 def do_get_language_info(parser, token): 139 """ 140 This will store the language information dictionary for the given language 141 code in a context variable. 142 143 Usage:: 144 145 {% get_language_info for language_code as l %} 146 {{ l.language_code }} 147 {{ l.name }} 148 {{ l.name_local }} 149 {{ l.bidi|yesno:"bi-directional,uni-directional" }} 150 """ 151 args = token.contents.split() 152 if len(args) != 5 or args[1] != 'for' or args[3] != 'as': 153 raise TemplateSyntaxError, "'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:]) 154 return GetLanguageInfoNode(args[2], args[4]) 155 156 def do_get_language_info_list(parser, token): 157 """ 158 This will store a list of language information dictionaries for the given 159 language codes in a context variable. The language codes can be specified 160 ither as a list of strings or a settings.LANGUAGES style tuple (or any 161 sequence of sequences whose first items are language codes). 162 163 Usage:: 164 165 {% get_language_info_list for LANGUAGES as langs %} 166 {% for l in langs %} 167 {{ l.language_code }} 168 {{ l.name }} 169 {{ l.name_local }} 170 {{ l.bidi|yesno:"bi-directional,uni-directional" }} 171 {% endfor %} 172 """ 173 args = token.contents.split() 174 if len(args) != 5 or args[1] != 'for' or args[3] != 'as': 175 raise TemplateSyntaxError, "'%s' requires 'for sequence as variable' (got %r)" % (args[0], args[1:]) 176 return GetLanguageInfoListNode(args[2], args[4]) 177 178 def language_name(lang_code): 179 return translation.get_language_info(lang_code)['name'] 180 181 def language_name_local(lang_code): 182 return translation.get_language_info(lang_code)['name_local'] 183 184 def language_bidi(lang_code): 185 return translation.get_language_info(lang_code)['bidi'] 186 110 187 def do_get_current_language(parser, token): 111 188 """ 112 189 This will store the current language in the context. … … 253 330 counter) 254 331 255 332 register.tag('get_available_languages', do_get_available_languages) 333 register.tag('get_language_info', do_get_language_info) 334 register.tag('get_language_info_list', do_get_language_info_list) 256 335 register.tag('get_current_language', do_get_current_language) 257 336 register.tag('get_current_language_bidi', do_get_current_language_bidi) 258 337 register.tag('trans', do_translate) 259 338 register.tag('blocktrans', do_block_translate) 339 340 register.filter(language_name) 341 register.filter(language_name_local) 342 register.filter(language_bidi) -
django/utils/translation/__init__.py
3 3 """ 4 4 from django.utils.functional import lazy 5 5 from django.utils.encoding import force_unicode 6 try: 7 from django.conf.language_info import language_info 8 except ImportError: 9 raise ImportError("Module django.conf.language_info not found. Run django/bin/make-language-info.py to generate it.") 6 10 7 11 __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext', 8 12 'ngettext_lazy', 'string_concat', 'activate', 'deactivate', … … 109 113 """ 110 114 return u''.join([force_unicode(s) for s in strings]) 111 115 string_concat = lazy(string_concat, unicode) 116 117 def get_language_info(lang_code): 118 try: 119 return language_info[lang_code] 120 except KeyError: 121 raise KeyError("Unknown language code %r. If you have added a new translation, remember to add the language to the LANGUAGES setting and update the django/conf/language_info.py file by running django/bin/make-language-info.py." % lang_code) -
django/bin/make-language-info.py
1 #!/usr/bin/env python 2 3 LANGUAGE_INFO_PY_FILE = 'django/conf/language_info.py' 4 5 # Need to ensure that the i18n framework is enabled 6 from django.conf import settings 7 settings.configure(USE_I18N = True) 8 9 TEMPLATE = """\ 10 # This file was generated with django/bin/make-language-info.py and it is not 11 # recommended to edit it by hand. For new translations, compile the new .po 12 # files and edit the LANGUAGES setting, and finally re-run 13 # django/bin/make-language-info.py to generate this file. 14 15 language_info = { 16 %s 17 } 18 """ 19 20 def make_language_info(target_path): 21 print 'Writing language information to\n%s' % target_path 22 # Create a dummy language_info.py file to make sure we can import the 23 # translation module. 24 file(target_path, 'w').write(TEMPLATE % '') 25 from django.utils import translation 26 from pprint import pformat 27 language_info = {} 28 for code, name in settings.LANGUAGES: 29 translation.activate(code) 30 language_info[code] = {"language_code": code, 31 "name": name, 32 "name_local": translation.ugettext(name), 33 "bidi": code in settings.LANGUAGES_BIDI} 34 file(target_path, 'w').write(TEMPLATE % pformat(language_info)[1:-1]) 35 # Because the timestamps of the dummy .pyc and real .py may fall on the 36 # same second, we must enforce compilation. 37 import py_compile 38 py_compile.compile(target_path) 39 print 'Done.' 40 41 42 if __name__ == "__main__": 43 from os.path import join, dirname, abspath 44 path = abspath(join(dirname(__file__), '..', '..', LANGUAGE_INFO_PY_FILE)) 45 make_language_info(path) -
tests/regressiontests/i18n/tests.py
1 1 # coding: utf-8 2 import misc 2 import misc, language_info 3 3 4 4 regressions = ur""" 5 5 Format string interpolation should work with *_lazy objects. … … 68 68 69 69 __test__ = { 70 70 'regressions': regressions, 71 'language_info': language_info.tests, 71 72 'misc': misc.tests, 72 73 } -
tests/regressiontests/templates/tests.py
776 776 'i18n17': ('{% load i18n %}{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'), 777 777 'i18n18': ('{% load i18n %}{% blocktrans with anton|force_escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'), 778 778 779 # retrieving language information 780 'i18n19': ('{% load i18n %}{% get_language_info for "de" as l %}{{ l.language_code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {}, 'de: German/Deutsch bidi=False'), 781 'i18n20': ('{% load i18n %}{% get_language_info for LANGUAGE_CODE as l %}{{ l.language_code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {'LANGUAGE_CODE': 'fi'}, 'fi: Finnish/suomi bidi=False'), 782 'i18n21': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.language_code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': ['it', 'no']}, 'it: Italian/Italiano bidi=False; no: Norwegian/Norsk bidi=False; '), 783 'i18n22': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.language_code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': (('sl', 'Slovenian'), ('fa', 'Persian'))}, 'sl: Slovenian/Slovenski bidi=False; fa: Persian/Persian bidi=True; '), 784 'i18n23': ('{% load i18n %}{{ "hu"|language_name }} {{ "hu"|language_name_local }} {{ "hu"|language_bidi }}', {}, 'Hungarian Magyar False'), 785 'i18n24': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, 'Dutch Nederlands False'), 786 779 787 ### HANDLING OF TEMPLATE_STRING_IF_INVALID ################################### 780 788 781 789 'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')), -
docs/i18n.txt
679 679 .. _session: ../sessions/ 680 680 .. _request object: ../request_response/#httprequest-objects 681 681 682 Local names of languages 683 ======================== 684 685 The ``get_language_info()`` function provides detailed information about 686 languages:: 687 688 >>> form django.utils.translation import get_language_info 689 >>> l = get_language_info('de') 690 >>> print l['name'], l['name_local'], l['bidi'] 691 German Deutsch False 692 693 The ``name`` and ``name_local`` attributes of the dictionary contain the name 694 of the language in English and the language itself, respectively. The ``bidi`` 695 attribute is True only for bi-directional languages. 696 697 In templates, you can use special template tags or filters to retrieve the same 698 information. To get information about a single language, use the 699 ``{% get_language_info %}`` tag:: 700 701 {% get_language_info for LANGUAGE_CODE as lang %} 702 {% get_language_info for "pl" as lang %} 703 704 You can then access the information:: 705 706 Language code: {{ lang.language_code }}<br /> 707 Name of language: {{ lang.name_local }}<br /> 708 Name in English: {{ lang.name }}<br /> 709 Bi-directional: {{ lang.bidi }} 710 711 You can also use the ``{% get_language_info_list %}`` template tag to retrieve 712 information for a list of languages (e.g. active languages as specified in 713 ``settings.LANGUAGES``). See `The set_language redirect view`_ for an example 714 of how to display a language selector using ``{% get_language_info_list %}``. 715 716 In addition to ``settings.LANGUAGES`` style nested tuples, 717 ``{% get_language_info_list %}`` supports simple lists of language codes. If 718 you do this in your view:: 719 720 return render_to_response('mytemplate.html', 721 {'available_languages': ['en', 'es', 'fr']}, 722 RequestContext(request)) 723 724 you can iterate those languages in the template:: 725 726 {% get_language_info_list available_languages %} 727 {% for l in available_languages %} ... {% endfor %} 728 729 There are also simple filters available for convenience: 730 731 * ``{{ LANGUAGE_CODE|language_name }}`` ("German") 732 * ``{{ LANGUAGE_CODE|language_name_local }}`` ("Deutsch") 733 * ``{{ LANGUAGE_CODE|bidi }}`` (False) 734 735 The source of the language information is the ``django.conf.language_info`` 736 module. If you add a new translation, you should run the 737 ``django/bin/make-language-info.py`` script to insert the information for the 738 added language. 739 682 740 Using translations in your own projects 683 741 ======================================= 684 742 … … 772 830 * If that's empty -- say, if a user's browser suppresses that header -- 773 831 then the user will be redirected to ``/`` (the site root) as a fallback. 774 832 775 Here's example HTML template code:: 833 Here's example HTML template code (see `Local names of languages`_ for more 834 information):: 776 835 836 {% get_language_info_list for LANGUAGES as available_languages %} 777 837 <form action="/i18n/setlang/" method="post"> 778 <input name="next" type="hidden" value="/next/page/" /> 779 <select name="language"> 780 {% for lang in LANGUAGES %} 781 <option value="{{ lang.0 }}">{{ lang.1 }}</option> 782 {% endfor %} 783 </select> 784 <input type="submit" value="Go" /> 838 <input name="next" type="hidden" value="/next/page/" /> 839 <select name="language"> 840 {% for lang in available_languages %} 841 <option value="{{ lang.language_code }}" {% ifequal lang.language_code LANGUAGE_CODE %}selected{% endifequal %}> 842 {{ lang.name_local }} 843 </option> 844 {% endfor %} 845 </select> 846 <input type="submit" value="Go" /> 785 847 </form> 786 848 787 849 Translations and JavaScript