def add_greeting(ctx: Context): ctx.assets["minecraft:en_us"] = Language({"greeting.hello": "hello"}) ctx.assets["minecraft:fr_fr"] = Language({"greeting.hello": "bonjour"}) ctx.data["greeting:hello"] = Function( ['tellraw @a {"translate": "greeting.hello"}'] * 5, tags=["minecraft:load"], )
def load_languages( path: FileSystemPath, dialect: Optional[DialectLike] = None, prefix: str = "", ) -> Dict[str, Language]: """Return a dictionnary mapping each column to a language file.""" with open(path, newline="") as csv_file: if not dialect: dialect = Sniffer().sniff(csv_file.read(1024)) csv_file.seek(0) reader = DictReader(csv_file, dialect=dialect) key, *language_codes = reader.fieldnames or [""] languages = {code: Language({}) for code in language_codes} for row in reader: if not (identifier := row[key]): continue identifier = prefix + identifier for code in language_codes: if value := row[code]: languages[code].data[identifier] = value else: msg = f"Locale {code!r} has no translation for {identifier!r}" logger.warning(msg)
def beet_default(ctx: Context): ctx.assets.language_config["aaaa"] = { "name": "AAAA name", "region": "AAAA region", "bidirectional": False, } ctx.assets["minecraft:aaaa"] = Language({"menu.singleplayer": "AAAA"})
def add_greeting_translations(ctx: Context): ctx.meta["greeting_translations"] = cast(JsonDict, {}) yield for key, translations in ctx.meta["greeting_translations"].items(): for code, value in translations.items(): ctx.assets.languages.merge( {f"minecraft:{code}": Language({f"greeting.{key}": value})})
def add_greeting_translations(ctx: Context): ctx.assets["minecraft:en_us"] = Language({"greeting.hello": "hello"}) ctx.assets["minecraft:fr_fr"] = Language({"greeting.hello": "bonjour"})