~ubuntu-branches/ubuntu/vivid/frescobaldi/vivid

« back to all changes in this revision

Viewing changes to frescobaldi_app/language_names/__init__.py

  • Committer: Package Import Robot
  • Author(s): Ryan Kavanagh
  • Date: 2012-01-03 16:20:11 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120103162011-tsjkwl4sntwmprea
Tags: 2.0.0-1
* New upstream release 
* Drop the following uneeded patches:
  + 01_checkmodules_no_python-kde4_build-dep.diff
  + 02_no_pyc.diff
  + 04_no_binary_lilypond_upgrades.diff
* Needs new dependency python-poppler-qt4
* Update debian/watch for new download path
* Update copyright file with new holders and years

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! python
 
2
 
 
3
"""
 
4
This module provides one function, languageName(), that returns
 
5
the human-readable name of a language from a codename (like 'nl').
 
6
 
 
7
The data is in the data.py file.
 
8
The file generate.py can be used by developers to (re-)generate
 
9
the data file.
 
10
 
 
11
Thanks go to the KDE developers for their translated language names
 
12
which are used currently in data.py.
 
13
 
 
14
"""
 
15
 
 
16
import itertools
 
17
import locale
 
18
from .data import language_names
 
19
 
 
20
__all__ = ['languageName']
 
21
 
 
22
 
 
23
def languageName(code, language=None):
 
24
    """Returns a human-readable name for a language.
 
25
    
 
26
    The language must be given in the 'code' attribute.
 
27
    The 'language' attribute specifies in which language
 
28
    the name must be translated and defaults to the current locale.
 
29
    
 
30
    """
 
31
    if language is None:
 
32
        language = locale.getdefaultlocale()[0] or "C"
 
33
        
 
34
    for lang in (language, language.split('_')[0], "C"):
 
35
        try:
 
36
            d = language_names[lang]
 
37
        except KeyError:
 
38
            continue
 
39
        
 
40
        for c in (code, code.split('_')[0]):
 
41
            try:
 
42
                return d[c]
 
43
            except KeyError:
 
44
                continue
 
45
        break
 
46
    return code
 
47
 
 
48