6.22.1. Run Time Phrase translation

Interscript can use tables of equivalent phases to translate parts of documents. These include fixed phrases such as 'Table of Contents', and variable phrases such as headings.

This mechanism is not suitable for bulk translation of paragraphs.

Interscript is written using English script. Therefore, the translation tables are dictionaries, one dictionary per phrase, keyed by language. A master dictionary is keyed by the English phrase, its value is the dictionary of translations.

Start python section to interscript/languages/__init__.py[1 /1 ]
     1: #line 20 "interscript_languages.ipk"
     2: # interscript languages
     3: import re
     4: 
End python section to interscript/languages/__init__.py[1]
Start python section to interscript/languages/interscript_languages.py[1 /1 ]
     1: #line 24 "interscript_languages.ipk"
     2: from interscript.encoding.utf8 import utf8
     3: import re
     4: 
     5: interscript_phrases = {
     6:   'Contents': {
     7:     'es': "Contenidos"
     8:    },
     9:   'Table of Contents': {
    10:     'es': 'Tabla de contenidos',
    11:     'it': 'Indice',
    12:     'pt':'\u00CDndicie',
    13:     'fr':'Table des mati\u00E8res',
    14:     'de':'Inhaltsverzeichnis'
    15:   },
    16:   'Next': {
    17:     'es': 'Siguiente',
    18:     'fr': 'Ensuite',
    19:     'de': 'Folgende',
    20:     'it': 'Seguente'
    21:   },
    22:   'Prev': {
    23:     'es': 'Previo',
    24:     'fr': 'Pr\u00E9c\u00E9dent',
    25:     'de': 'Vorige'
    26:   },
    27:   'First': {
    28:     'es': 'Primero',
    29:     'de': 'Erste',
    30:     'fr': 'Premi\u00E8re',
    31:     'it': 'Primo',
    32:     'pt': 'Primeira',
    33:     'el': '\u03A0\u03C1\u03CE\u03C4\u03B7',
    34:     'nl': 'Eerste'
    35:   },
    36:   'Last': {
    37:     'es': '\u00DAltimo',
    38:     'fr':'Dernier'
    39:   },
    40:   'Classes': {
    41:     'es': "Clases",
    42:     'de': 'Kategorien',
    43:     'it': 'Codici Categoria'
    44:   },
    45:   'Functions': {
    46:     'es': "Funciones",
    47:     'de':'Funktionen'
    48:   },
    49:   'Top': {
    50:     'es': "Arriba del todo",
    51:     'fr':'Dessus',
    52:     'de':'Oberseite'
    53:   },
    54:   'Upmost': {
    55:     'es': 'Arriba del todo'
    56:   },
    57:   'Sources': {
    58:     'es': 'Fuentes',
    59:     'de':'Quellen'
    60:   },
    61:   'Identifiers': {
    62:     'es': "Identificadores"
    63:   },
    64:   'Version': {
    65:     'es': 'Versi\u00F3n'
    66:   },
    67:   'Installation': {
    68:     'es': 'Instalación'
    69:   },
    70:   'Requirements': {
    71:     'es': 'Requerimientos'
    72:   },
    73:   'Tests': {
    74:     'de':'Pr\u00FCfen'
    75:   },
    76:   'section': {
    77:     'es': "seccione",
    78:     'it':'sezione'
    79:   },
    80:   'Sections': {
    81:     'es': "Secciones"
    82:   },
    83:   'Tutorial': {
    84:     'fr':"Cours d\u0301instruction"
    85:   },
    86:   'Code': {
    87:     'es':'Código'
    88:   },
    89:   'Start': {
    90:     'es':'Comienzo',
    91:     'de':'Beginnen',
    92:     'pt':'C\u00E7meco',
    93:     },
    94:   'End': {
    95:     'es': 'Fin',
    96:     'it':'estremit\u00E0',
    97:     'de':'Ende',
    98:     'pt':'Extremidade'
    99:   }
   100: }
   101: 
   102: slash_u = re.compile(r'\\u(....)|\\U(........)')
   103: 
   104: def parse_escapes(text):
   105:   pos = 0
   106:   s = ''
   107:   match = slash_u.search(text,pos)
   108:   while match:
   109:     first, last = match.start(0), match.end(0)
   110:     s = s + text[pos:first]
   111:     if match.group(1): hexcode = match.group(1)
   112:     else: hexcode = match.group(2)
   113:     value = hexval(hexcode)
   114:     utf = utf8(value)
   115:     s = s + utf
   116:     pos = last
   117:     match = slash_u.search(text,pos)
   118:   s = s + text[pos:]
   119:   return s
   120: 
   121: def tr_phrase(native_phrase, language):
   122:   x = parse_escapes(native_phrase)
   123:   d = interscript_phrases.get(x,{})
   124:   tr = d.get(language,x)
   125:   return parse_escapes(tr)
   126: 
   127: def phrase_list():
   128:   keys = interscript_phrases.keys()
   129:   keys.sort()
   130:   return keys
   131: 
   132: def add_translation(native_phrase, **kwds):
   133:   if not interscript_phrases.has_key(native_phrase):
   134:     interscript_phrases[native_phrase]={}
   135:   interscript_phrases[native_phrase].update(kwds)
   136: 
   137: 
End python section to interscript/languages/interscript_languages.py[1]