def _add_contents(self, file): instance = LangStrings(file.replace(TRANSLATION_PATH, "")[1:~3]) for key, value in instance.items(): if key in self: warn('Translation key "{translation_key}" ' "already registered.".format(translation_key=key)) continue self[key] = value
def __init__(self): """Retrieve all core translations and store them in the dictionary.""" # Initialize the dictionary super().__init__() # Create base dictionaries to store message hooks self._hooked_messages = defaultdict(list) self._hooked_prefixes = defaultdict(list) # Loop through all message translation files message_path = GUNGAME_TRANSLATION_PATH / 'messages' for file in message_path.walkfiles('*.ini'): # Skip all server-specific files if file.namebase.endswith('_server'): continue # Get the current translations instance = LangStrings( file.replace(TRANSLATION_PATH, '')[1:~3] ) # Loop through all translations in the current file for key, value in instance.items(): # Verify that the name is unique if key in self: warn(f'Translation key "{key}" already registered.') continue # Add the translations to the dictionary self[key] = value
def _add_contents(self, file): instance = LangStrings( file.replace(TRANSLATION_PATH, '')[1:~3] ) for key, value in instance.items(): if key in self: warn(f'Translation key "{key}" already registered.') continue self[key] = value
def __init__(self, name, path): self.name = name self.type = None self.module = None with open(path / name / 'config.json') as inputfile: self.config = json_load(inputfile) self.strings = LangStrings(path / name / 'strings') self.config['categories'] = []
def __init__(self, path, encoding='utf-8', comment_prefix='//', as_strings=False): """Parses the given configuation file path. :param Path path: The path of the file to parse. :param str encoding: The encoding to use when opening the file. :param str comment_prefix: The prefix of end line comments. :param bool as_strings: Whether the parsed lines should be stored as strings rather than argument lists. """ # If the given path doesn't exist, search for it in the cfg directory if not path.isfile(): path = CFG_PATH.joinpath(path) # If no file was found, return an empty list if not path.isfile(): return # Import this here to fix cyclic imports from translations.strings import LangStrings # Open the given file and parse its content with open(path, 'r', encoding=encoding) as f: # Loop through all lines for line in f.read().splitlines(): # Parse the argument from the current line args = Tokenize(LangStrings._replace_escaped_sequences(line), comment_prefix) # Skip empty/commented lines if not args: continue # Add the current line to the list self.append(args if not as_strings else str(args))
# ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python from colors import Color from translations.strings import LangStrings # PLRBots from ..info import info # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Map color variables in translation files to actual Color instances COLOR_SCHEME = { 'color_tag': Color(242, 242, 242), 'color_highlight': Color(0, 250, 190), 'color_default': Color(242, 242, 242), 'color_error': Color(255, 54, 54), } common_strings = LangStrings(info.name + "/strings") config_strings = LangStrings(info.name + "/config")
## IMPORTS from translations.strings import LangStrings from .config import MESSAGE_TYPE ## ALL DECLARATION __all__ = ( 'strings', 'show_experience', 'give_experience', 'take_experience', ) ## GLOBALS strings = LangStrings('warcraft') ## MESSAGE DEFINITION show_experience = MESSAGE_TYPE(message=strings['show_experience']) give_experience = MESSAGE_TYPE(message=strings['give_experience']) take_experience = MESSAGE_TYPE(message=strings['take_experience'])
# Source.Python from menus import PagedMenu as SpPagedMenu from menus import PagedOption from menus import Text from menus.base import _translate_text from translations.strings import LangStrings # ====================================================================== # >> GLOBALS # ====================================================================== _lang_strings = LangStrings('xtend/menus') # ====================================================================== # >> CLASSES # ====================================================================== class PagedMenu(SpPagedMenu): """ Extend's Source.Python's default menus package with new features and functionality, such as - constants: Display same option on all pages - previous_menu: presssing "Previous" on the first page - next_menu: pressing "Next" on the last page - display_page_info: Display the page number in top right corner """
# ============================================================================= # >> CONSTANTS # ============================================================================= STUCK_RELEASE_TIMEOUT = 4.0 VEC_P2P_OFFSET = Vector(0, 0, 80) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= saved_locs = PlayerDictionary(lambda index: None) selected_p2p_first = PlayerDictionary(lambda index: None) # ============================================================================= # >> TRANSLATION # ============================================================================= LANG = LangStrings(info.basename) SAY_PLAYER_DISCONNECT = SayText2(LANG["player_disconnected"]) SAY_LOC_SAVED = SayText2(LANG["loc_saved"]) SAY_NO_LOC_SAVED = SayText2(LANG["no_loc_saved"]) SAY_SELF_TELEPORTED_TO = SayText2(LANG["self_teleported_to"]) SAY_TELEPORTED_TO_ME = SayText2(LANG["teleported_to_me"]) SAY_TELEPORTED_TO_SAVED_RS = SayText2(LANG["teleport_to_saved_rs"]) SAY_TOGGLE_DISABLED = SayText2(LANG["auto_toggle_disable"]) SAY_TOGGLE_ENABLED = SayText2(LANG["auto_toggle_enable"]) SAY_SAVE_LOCATION_FIRST = SayText2(LANG["save_location_first"]) # ============================================================================= # >> FUNCTIONS # ============================================================================= def save_location(player: Player):
# ============================================================================ # Source.Python Imports # Translations from translations.strings import LangStrings # WCS Imports # Constants from ..constants.paths import TRANSLATION_PATH # ============================================================================ # >> ALL DECLARATION # ============================================================================ __all__ = ( 'categories_strings', 'chat_strings', 'config_strings', 'menu_strings', ) # ============================================================================ # >> GLOBAL VARIABLES # ============================================================================ # Language strings for the UI categories_strings = LangStrings(TRANSLATION_PATH / 'categories_strings') # Language strings for the chat chat_strings = LangStrings(TRANSLATION_PATH / 'chat_strings') # Language strings for the configuration config_strings = LangStrings(TRANSLATION_PATH / 'config_strings') # Language strings for the menus menu_strings = LangStrings(TRANSLATION_PATH / 'menu_strings')
# Players from players.entity import Player from players.helpers import index_from_userid # Settings from settings.player import PlayerSettings # Translations from translations.strings import LangStrings # Script Imports from most_damage.info import info # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the translations most_damage_strings = LangStrings(info.basename) # Get the message instances most_damage_messages = { 1: HintText(most_damage_strings[info.name]), 2: TextMsg(most_damage_strings[info.name], HudDestination.CENTER), 4: KeyHintText(most_damage_strings[info.name]), } # Create the user settings user_settings = PlayerSettings(info.name, 'md') # Get the human player index iterator _human_players = PlayerIter('human') # Store the possible options
# Source.Python from menus import SimpleMenu from menus import SimpleOption from menus import PagedOption from menus import Text from menus.base import _translate_text from translations.strings import LangStrings # ====================================================================== # >> GLOBALS # ====================================================================== _TR = LangStrings('hw/menus') menus = {} # ====================================================================== # >> CLASSES # ====================================================================== class HeroMenu(PagedMenu): """ Extends regular xtend's PagedMenu to accept hero argument. - hero: Hero class or instance - option7: shortcut property for binding constants[7] """
from paths import TRANSLATION_PATH # Translations from translations.strings import LangStrings # Script Imports from victim_stats.info import info # ============================================================================= # >> SUPPORT VERIFICATION # ============================================================================= # Verify that the engine is supported if not TRANSLATION_PATH.joinpath( info.basename, '{0}.ini'.format(SOURCE_ENGINE)).isfile(): raise NotImplementedError( 'Engine "{0}" not supported'.format(SOURCE_ENGINE)) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the translations victim_stats_strings = LangStrings('{0}/strings'.format(info.basename)) # Merge in the engine specific translations victim_stats_strings.update( LangStrings('{0}/{1}'.format(info.basename, SOURCE_ENGINE))) # Get the hitgroup translations hitgroup_strings = LangStrings('{0}/hitgroups'.format(info.basename))
# ../dissolver/strings.py """Contains all translation variables for the base plugin.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python from translations.strings import LangStrings # Plugin from .info import info # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'CONFIG_STRINGS', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= CONFIG_STRINGS = LangStrings(f'{info.name}')
# ../hooks/__init__.py """Provides warnings and exceptions hooking functionality.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python Imports # Loggers from loggers import _sp_logger # Translations from translations.strings import LangStrings # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the hooks strings _hooks_strings = LangStrings('_core/hooks_strings') # Get the sp.hooks logger hooks_logger = _sp_logger.hooks
# ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'disabled_punishments', 'disabled_rewards', 'percent_for_both', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= _config_strings = LangStrings(info.basename) _base_path = Path(__file__).parent # ============================================================================= # >> REGISTRATION # ============================================================================= for _type in ('punishments', 'rewards'): for _file in _base_path.joinpath(_type).files('*.py'): if _file.namebase == '__init__': continue import_module( _file.replace( _base_path.parent, '' )[1:-3].replace('/', '.').replace('\\', '.')
from players.entity import Player from players.helpers import index_from_userid # Settings from settings.player import PlayerSettings # Translations from translations.strings import LangStrings # Script Imports from most_damage.info import info # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the translations most_damage_strings = LangStrings(info.basename) # Get the message instances most_damage_messages = { 1: HintText(most_damage_strings[info.name]), 2: TextMsg(most_damage_strings[info.name], HudDestination.CENTER), 4: KeyHintText(most_damage_strings[info.name]), } # Create the user settings user_settings = PlayerSettings(info.name, 'md') # Get the human player index iterator _human_players = PlayerIter('human') # Store the possible options
from warcraft.experience import kill_reason, headshot_reason, win_reason from warcraft.players import player_dict ## extension imports from .config import ( experience_for_kill, experience_for_headshot, experience_for_win ) from .file import get_rotd_classes, randomise_rotd_classes, write_to_rotd_file ## globals rotd_strings = LangStrings("warcraft/extensions/rotd") rotd_advert_message = SayText2(message=rotd_strings["advert"]) rotd_broadcast_message = SayText2(message=rotd_strings["broadcast"]) rotd_broadcast_plural_message = SayText2(message=rotd_strings["broadcast_plural"]) rotd_experience_up = SayText2(message=rotd_strings["experience_up"]) ## handlers @OnLevelInit def _on_level_init_check_day(map_name): date = datetime.today().strftime('%Y-%m-%d') if rotd_date != date: randomise_rotd_classes() with rotd_file.open("a+") as rotd_fp: write_to_rotd_file(rotd_fp)
# ../dnd5e/core/strings.py # Source.Python from paths import TRANSLATION_PATH from translations.strings import LangStrings __all__ = ('CHALLENGE_STRINGS', 'MENU_STRINGS') CHALLENGE_STRINGS = LangStrings(TRANSLATION_PATH / 'dnd5e' / 'challenge_strings') MENU_STRINGS = LangStrings(TRANSLATION_PATH / 'dnd5e' / 'menu_strings')
## IMPORTS from commands import CommandReturn from commands.say import SayCommand from messages import SayText2 from players.entity import Player from translations.strings import LangStrings ## GLOBALS strings = LangStrings('resetscore') ## SAY REGISTERS @SayCommand(['!rs', '/rs', '!resetscore', '/resetscore']) def _resetscrore_say_command(command, index, team_only=None): player = Player(index) if player.kills != 0 or player.deaths != 0: player.kills = 0 player.deaths = 0 SayText2(strings['Resetscore']).send(player.index) else: SayText2(strings['Already']).send(player.index) return CommandReturn.BLOCK
from .info import info from .manager import choice_manager # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'disabled_punishments', 'disabled_rewards', 'percent_for_both', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= _config_strings = LangStrings(info.name + '/config') _base_path = Path(__file__).parent # ============================================================================= # >> REGISTRATION # ============================================================================= for _type in ('punishments', 'rewards'): for _file in _base_path.joinpath(_type).files('*.py'): if _file.namebase == '__init__': continue import_module( _file.replace(_base_path.parent, '')[1:-3].replace('/', '.').replace('\\', '.')) # ============================================================================= # >> CONFIGURATION
# ../most_damage/strings.py """Contains all translation variables for the base plugin.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python from translations.strings import LangStrings # Plugin from .info import info # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'CONFIG_STRINGS', 'MESSAGE_STRINGS', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= CONFIG_STRINGS = LangStrings(f'{info.name}/config_strings') MESSAGE_STRINGS = LangStrings(f'{info.name}/strings')
info = PluginInfo() info.name = 'Warcraft: GO' info.author = 'Mahi' info.version = '0.6.1' info.basename = 'wcgo' info.variable = "{0}_version".format(info.basename) # Public variable for plugin info info.convar = PublicConVar(info.variable, info.version, 0, "{0} Version".format(info.name)) # Experience Values exp_values = cfg._retrieve_exp_values(cfg.exp_multiplier) # Translation messages exp_messages = get_messages(LangStrings('wcgo/exp'), HintText) gold_messages = get_messages(LangStrings('wcgo/gold'), SayText2) other_messages = get_messages(LangStrings('wcgo/other'), SayText2) # ====================================================================== # >> FUNCTIONS # ====================================================================== def load(): """Setups the database upon sp load. Makes sure there are heroes on the server, restarts the game and setups the database file. Raises:
# ../death_beam/strings.py """Contains all translation variables for the base plugin.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python from translations.strings import LangStrings # Plugin from .info import info # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'CONFIG_STRINGS', 'TRANSLATION_STRINGS', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= CONFIG_STRINGS = LangStrings(f'{info.name}/config_strings') TRANSLATION_STRINGS = LangStrings(f'{info.name}/strings')
## IMPORTS from messages import SayText2 from translations.strings import LangStrings ## ALL DECLARATION __all__ = ('g_hitgroups_name', 'g_damage_message') ## GLOBALS strings = LangStrings('showdamage') ## MESSAGE DEFINITION g_hitgroups_name = [ strings['Generic'], strings['Head'], strings['Chest'], strings['Stomach'], strings['Left Arm'], strings['Right Arm'], strings['Left Leg'], strings['Right Leg'] ] g_damage_message = { 1: { 'full': strings['Show Damage Chat Full'], 'hitgroup': strings['Show Damage Chat Hitgroup'], 'armor': strings['Show Damage Chat Armor'], 'damage': strings['Show Damage Chat Damage'] }, 2: { 'full': strings['Show Damage Hint Full'], 'hitgroup': strings['Show Damage Hint Hitgroup'],
# ../throw_melee/strings.py """.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python from translations.strings import LangStrings # Plugin from .info import info # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ( 'CONFIG_STRINGS', 'MESSAGE_STRINGS', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= CONFIG_STRINGS = LangStrings(info.name + '/config_strings') MESSAGE_STRINGS = LangStrings(info.name + '/strings')
from .est.commands import armor_command # Just to load it from .est.effects import effect101 # Just to load it from ..wards import DamageWard from ..wards import ward_manager # Players from ...players import team_data from ...players.entity import Player as WCSPlayer # ============================================================================ # >> GLOBAL VARIABLES # ============================================================================ _aliases = {} if (TRANSLATION_PATH / 'strings.ini').isfile(): _strings = LangStrings(TRANSLATION_PATH / 'strings') for key in _strings: for language, message in _strings[key].items(): _strings[key][language] = message.replace('#default', COLOR_DEFAULT).replace('#green', COLOR_GREEN).replace('#lightgreen', COLOR_LIGHTGREEN).replace('#darkgreen', COLOR_DARKGREEN) else: _strings = None _restrictions = WeaponRestrictionHandler() _all_weapons = set([x.basename for x in WeaponClassIter('all', ['melee', 'objective'])]) if (CFG_PATH / 'es_WCSlanguage_db.txt').isfile(): _languages = KeyValues.load_from_file(CFG_PATH / 'es_WCSlanguage_db.txt').as_dict() else: _languages = {}
# Paths from paths import CFG_PATH # Translations from translations.strings import LangStrings from translations.strings import TranslationStrings # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ('ConfigManager', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the config language strings _config_strings = LangStrings('_core/config_strings') # ============================================================================= # >> CLASSES # ============================================================================= class ConfigManager(object): """Config Management class used to create a config file.""" def __init__(self, filepath, cvar_prefix='', indention=3, max_line_length=79): """Initialized the configuration manager. :param str filepath:
def _get_messages(translation_file, message_cls): """Get a dict of messages from a translation file.""" lang_strings = LangStrings(info.basename + '/' + translation_file) return {key: message_cls(value) for key, value in lang_strings.items()}
# ../plugins/__init__.py """Provides an interface to load/unload plugins.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python Imports # Loggers from loggers import _sp_logger # Translations from translations.strings import LangStrings # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the plugin strings _plugin_strings = LangStrings('_core/plugin_strings') # Get the sp.plugins logger plugins_logger = _sp_logger.plugins
from configobj import ConfigObj # Source.Python Imports # Core from core.logger import core_logger # Paths from paths import GAME_PATH from paths import CFG_PATH # Translations from translations.strings import LangStrings # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the core settings language strings _core_strings = LangStrings('_core/core_settings_strings') # Get the sp.core.settings logger core_settings_logger = core_logger.settings # ============================================================================= # >> CLASSES # ============================================================================= class _CoreSettings(ConfigObj): """Class used to store core settings.""" def __init__(self, infile, *args, **kwargs): """Add missing items and set comments using the server's language.""" # Import the file super().__init__(infile, *args, **kwargs) self._language = None
# ../addons/source-python/packages/custom/cvartools/translations.py """Translations for Cvar Tools.""" # ============================================================================= # >> IMPORTS # ============================================================================= # Source.Python Imports # Translations from translations.strings import LangStrings # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= cvartools_strings = LangStrings("cvartools/strings")
def _save_player_data(player): """Save player's RPG data into the database.""" _database.save_player_data(player.steamid, player.level, player.xp, player.credits) for skill in player.skills: _database.save_skill_data(player.steamid, skill.class_id, skill.level) # ====================================================================== # >> GLOBALS # ====================================================================== _database = rpg.database.Database(PLUGIN_DATA_PATH / 'rpg.db') _players = PlayerDictionary(_new_player) _tr = LangStrings('rpg') # ====================================================================== # >> DATABASE FUNCTIONS # ====================================================================== def unload(): """Store players' data and close the the database.""" _data_save_repeat.stop() _save_everyones_data() _database.close() @Event('player_disconnect') def _save_player_data_upon_disconnect(event):
# Source.Python from messages import SayText2 from paths import TRANSLATION_PATH from translations.strings import LangStrings # Plugin from ..info import info # ============================================================================= # >> ALL DECLARATION # ============================================================================= __all__ = ('punishment_messages', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= punishment_messages = {} _punishment_path = TRANSLATION_PATH / info.name / 'punishments' for _ini_file in _punishment_path.files('*.ini'): if _ini_file.namebase.endswith('_server'): continue _instance = LangStrings(_ini_file.replace(TRANSLATION_PATH, '')[1:~3]) for _key, _value in _instance.items(): if _key in punishment_messages: warn('Translation key "{key}" is already registered.'.format( key=_key, )) continue punishment_messages[_key] = SayText2(_value)
## IMPORTS from events import Event from filters.players import PlayerIter from listeners import OnLevelInit from listeners.tick import Repeat from messages import SayText2, HintText, HudMsg from paths import PLUGIN_DATA_PATH from translations.strings import LangStrings from .info import info from .configs import _configs __all__ = ( 'NOT_FOUND', 'ADVERT_TRANSLATION', ) ## GLOBALS strings = LangStrings('advertisement') NOT_FOUND = strings['Not Found'] ADVERT_TRANSLATION = strings
""" """ ## source.python imports from translations.strings import LangStrings ## __all__ declaration __all__ = ("admin_strings", "admin_menu_strings", "categories_strings", "changerace_menu_strings", "experience_strings", "home_menu_strings", "playerinfo_menu_strings", "shopinfo_menu_strings", "shop_menu_strings", "raceinfo_menu_strings", "spendskills_menu_strings") ## translation loading admin_strings = LangStrings("warcraft/admin") experience_strings = LangStrings("warcraft/experience") admin_menu_strings = LangStrings("warcraft/menus/admin") categories_strings = LangStrings("warcraft/menus/categories") changerace_menu_strings = LangStrings("warcraft/menus/changerace") home_menu_strings = LangStrings("warcraft/menus/home") playerinfo_menu_strings = LangStrings("warcraft/menus/playerinfo") shop_menu_strings = LangStrings("warcraft/menus/shop") shopinfo_menu_strings = LangStrings("warcraft/menus/shopinfo") spendskills_menu_strings = LangStrings("warcraft/menus/spendskills") raceinfo_menu_strings = LangStrings("warcraft/menus/raceinfo")