<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> import os <EOL> import glob <EOL> from . import deco <EOL> from . import sys_info <EOL> from . import language_file <EOL> from . import settings <EOL> @ deco . singleton <EOL> class I18N ( object ) : <EOL> def __init__ ( self ) : <EOL> self . load ( ) <EOL> def load ( self ) : <EOL> self . lang_params = { } <EOL> self . lang_ids = [ ] <EOL> self . id_path_dict = { } <EOL> self . trans_dict = { } <EOL> self . list_ids ( ) <EOL> self . settings = settings . get_arduino_settings ( ) <EOL> self . lang_id = self . settings . get ( <EOL> '<STR_LIT>' , sys_info . get_sys_language ( ) ) <EOL> self . change_lang ( self . lang_id ) <EOL> def list_ids ( self ) : <EOL> self . lang_params = settings . get_user_settings ( <EOL> '<STR_LIT>' ) <EOL> preset_paths = [ settings . get_preset_path ( ) , <EOL> settings . get_user_preset_path ( ) ] <EOL> for preset_path in preset_paths : <EOL> lang_file_paths = glob . glob ( preset_path + '<STR_LIT>' ) <EOL> lang_file_names = [ os . path . basename ( p ) for p in lang_file_paths ] <EOL> self . lang_ids += [ name [ <NUM_LIT:5> : - <NUM_LIT:4> ] for name in lang_file_names ] <EOL> self . id_path_dict . update ( dict ( zip ( self . lang_ids , lang_file_paths ) ) ) <EOL> self . lang_ids . sort ( key = lambda _id : self . lang_params . get ( _id ) [ <NUM_LIT:1> ] ) <EOL> def change_lang ( self , lang_id ) : <EOL> if lang_id in self . id_path_dict : <EOL> self . lang_id = lang_id <EOL> lang_file_path = self . id_path_dict [ lang_id ] <EOL> lang_file = language_file . LanguageFile ( lang_file_path ) <EOL> self . trans_dict = lang_file . get_trans_dict ( ) <EOL> else : <EOL> self . lang_id = '<STR_LIT>' <EOL> self . trans_dict = { } <EOL> self . settings . set ( '<STR_LIT>' , self . lang_id ) <EOL> def translate ( self , text , * params ) : <EOL> trans_text = self . trans_dict . get ( text , text ) <EOL> for seq , param in enumerate ( params ) : <EOL> seq_text = '<STR_LIT>' % seq <EOL> trans_text = trans_text . replace ( seq_text , str ( param ) ) <EOL> return trans_text <EOL> def get_lang_id ( self ) : <EOL> return self . lang_id <EOL> def get_lang_ids ( self ) : <EOL> return self . lang_ids <EOL> def get_lang_names ( self , lang_id ) : <EOL> return self . lang_params . get ( lang_id , [ '<STR_LIT>' , '<STR_LIT>' ] ) </s>
