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 _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()}
# 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)
# 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 _options = {int( item.split(':')[1]): value for item, value in most_damage_strings.items( ) if item.startswith('Option:')} # ============================================================================= # >> CONFIGURATION # ============================================================================= # Create the most_damage.cfg file and execute it upon __exit__ with ConfigManager(info.basename) as config: # Create the default location convar default_location = config.cvar( 'md_default_location', 1, most_damage_strings['Default Location']) # Loop through the possible location options for _item, _value in sorted(_options.items()):
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 _options = { int(item.split(':')[1]): value for item, value in most_damage_strings.items() if item.startswith('Option:') } # ============================================================================= # >> CONFIGURATION # ============================================================================= # Create the most_damage.cfg file and execute it upon __exit__ with ConfigManager(info.basename) as config: # Create the default location convar default_location = config.cvar('md_default_location', 1, most_damage_strings['Default Location']) # Loop through the possible location options for _item, _value in sorted(_options.items()):