def _load_recent(self): code_pairs = pan_app.settings.language['recentlangs'].split('|') codes = [pair.split(',') for pair in code_pairs] if codes == [['']]: return [] recent_pairs = [] for srccode, tgtcode in codes: srclang = LanguageModel(srccode) tgtlang = LanguageModel(tgtcode) recent_pairs.append((srclang, tgtlang)) return recent_pairs
def _on_addlang_clicked(self, button): if not self.add_dialog.run(): return err = self.add_dialog.check_input_sanity() if err: self.controller.main_controller.show_error(err) return name = self.add_dialog.langname code = self.add_dialog.langcode nplurals = self.add_dialog.nplurals plural = self.add_dialog.plural if self.add_dialog.langcode in LanguageModel.languages: raise Exception('Language code %s already used.' % (code)) LanguageModel.languages[code] = (name, nplurals, plural) self.controller.new_langs.append(code) # Reload the language data in the selection dialog. self.select_dialog.clear_langs() langs = [LanguageModel(lc) for lc in LanguageModel.languages] langs.sort(key=lambda x: x.name) self.select_dialog.update_languages(langs)
def _set_source_lang(self, lang): if isinstance(lang, basestring): lang = LanguageModel(lang) if not lang or lang == self._source_lang: return self._source_lang = lang self.emit('source-lang-changed', self._source_lang.code)
def get_detected_langs(self): store = self.main_controller.store_controller.store if not store: return None if not self.lang_identifier: from translate.lang.identify import LanguageIdentifier self.lang_identifier = LanguageIdentifier() srccode = self.lang_identifier.identify_source_lang(store.get_units()) tgtcode = self.lang_identifier.identify_target_lang(store.get_units()) srclang = tgtlang = None if srccode: srclang = LanguageModel(srccode) if tgtcode: tgtlang = LanguageModel(tgtcode) return srclang, tgtlang
def set_language_pair(self, srclang, tgtlang): if isinstance(srclang, basestring): srclang = LanguageModel(srclang) if isinstance(tgtlang, basestring): tgtlang = LanguageModel(tgtlang) pair = (srclang, tgtlang) if pair in self.recent_pairs: self.recent_pairs.remove(pair) self.recent_pairs.insert(0, pair) self.recent_pairs = self.recent_pairs[:self.NUM_RECENT] self.source_lang = srclang self.target_lang = tgtlang self.view.update_recent_pairs() if self.source_lang == self.target_lang: self.view.notify_same_langs()
def _create_dialogs(self): from widgets.langselectdialog import LanguageSelectDialog from widgets.langadddialog import LanguageAddDialog langs = [LanguageModel(lc) for lc in LanguageModel.languages] langs.sort(key=lambda x: x.name) self.select_dialog = LanguageSelectDialog( langs, parent=self.controller.main_controller.view.main_window) self.select_dialog.btn_add.connect('clicked', self._on_addlang_clicked) self.add_dialog = LanguageAddDialog(parent=self.select_dialog.dialog)
def _init_langs(self): try: self._source_lang = LanguageModel( pan_app.settings.language['sourcelang']) except Exception: self._source_lang = None try: self._target_lang = LanguageModel( pan_app.settings.language['targetlang']) except Exception: self._target_lang = None # Load previously-saved (new) languages filename = os.path.join(pan_app.get_config_dir(), 'langs.ini') if os.path.isfile(filename): languages = pan_app.load_config(filename) for code in languages: languages[code] = (languages[code]['name'], int(languages[code]['nplurals']), languages[code]['plural']) LanguageModel.languages.update(languages)