def OnOperatorCommand(nick, data): global _ # has to be global, because we assign it here if data[1:].startswith("tr_example "): lang = data[1 + len("tr_example "):] if lang == "en": # Reset translations to default English: _ = update_translation_strings(english_strings) vh.usermc(_("OK, English now!"), nick) elif lang == "de": # Load German from our local dictionary, but copy it first so it is not overwritten. # (Missing or bad strings would be replaced by English versions, and extra strings would be removed.) # If you don't care about german_strings being modified, you can leave out the ".copy()". # _ = update_translation_strings(english_strings, german_strings.copy(), use_translated=True) vh.usermc(_("OK, English now!"), nick) # This will show up in German! elif lang == "database": # Load whatever language is used in the strings stored in the database: _ = update_translation_strings(english_strings, db_table=translation_db_table) vh.usermc(_("OK, English now!"), nick) # Anything is possible here elif lang == "file": # Load whatever language is used in the translation file: _ = update_translation_strings(english_strings, filename=translation_file, create=False) vh.usermc(_("OK, English now!"), nick) # Anything is possible here else: vh.usermc(_("Sorry, but I speak only %s.") % "en, de, database, file", nick) return 0
3: "Jawohl, jetzt Deutsch!", 4: "Ich schalte aus...", } # Replace this with your script's unique table name: translation_db_table = "translation_example_py_strings" # Replace this with path to your script's translation strings file: translation_file = vh.basedir + "/scripts/my_translations.txt" # This would only prepare the English strings for use with _[text]: # _ = update_translation_strings(english_strings) # This loads the default strings from the database in whatever language is stored there: _ = update_translation_strings(english_strings, db_table=translation_db_table) # This will print in English or the language in the database if the table already existed: vh.classmc(_("Script %s is ready.") % my_name, 3, 10) def OnOperatorCommand(nick, data): global _ # has to be global, because we assign it here if data[1:].startswith("tr_example "): lang = data[1 + len("tr_example "):] if lang == "en": # Reset translations to default English: _ = update_translation_strings(english_strings) vh.usermc(_("OK, English now!"), nick)