diff --git a/beet/contrib/babelbox.py b/beet/contrib/babelbox.py index 6778f14f..4a6af866 100644 --- a/beet/contrib/babelbox.py +++ b/beet/contrib/babelbox.py @@ -39,6 +39,7 @@ class BabelboxOptions(PluginOptions): dialect: Optional[str] = None namespace: str = "minecraft" filename_prefix: bool = False + unicode_escape: bool = False def beet_default(ctx: Context): @@ -57,6 +58,7 @@ def babelbox(ctx: Context, opts: BabelboxOptions): path=path, dialect=opts.dialect, prefix=Path(path).stem + "." if opts.filename_prefix else "", + unicode_escape=opts.unicode_escape, ) ) @@ -65,6 +67,7 @@ def load_languages( path: FileSystemPath, dialect: Optional[DialectLike] = None, prefix: str = "", + unicode_escape: bool = False, ) -> Dict[str, Language]: """Return a dictionnary mapping each column to a language file.""" with open(path, encoding="utf-8", newline="") as csv_file: @@ -85,6 +88,8 @@ def load_languages( for code in language_codes: if value := row[code]: + if unicode_escape: + value = value.encode("utf-8").decode("unicode_escape") languages[code].data[identifier] = value else: logger.warning( diff --git a/examples/load_babelbox/beet.json b/examples/load_babelbox/beet.json index ef533377..b76ec0da 100644 --- a/examples/load_babelbox/beet.json +++ b/examples/load_babelbox/beet.json @@ -25,6 +25,15 @@ "namespace": "demo" } } + }, + { + "pipeline": ["beet.contrib.babelbox"], + "meta": { + "babelbox": { + "load": ["unicode_escape.csv"], + "unicode_escape": true + } + } } ] } diff --git a/examples/load_babelbox/unicode_escape.csv b/examples/load_babelbox/unicode_escape.csv new file mode 100644 index 00000000..f9840802 --- /dev/null +++ b/examples/load_babelbox/unicode_escape.csv @@ -0,0 +1,3 @@ +id,en_us +entity.gm4.congealed_shard,"Congealed Soul Shard\u00A7" +entity.gm4.fire_sprite,"Fire Sprite ""named bob""" diff --git a/tests/snapshots/examples__build_load_babelbox__1.resource_pack/assets/minecraft/lang/en_us.json b/tests/snapshots/examples__build_load_babelbox__1.resource_pack/assets/minecraft/lang/en_us.json index 4a0f28a1..83753f90 100644 --- a/tests/snapshots/examples__build_load_babelbox__1.resource_pack/assets/minecraft/lang/en_us.json +++ b/tests/snapshots/examples__build_load_babelbox__1.resource_pack/assets/minecraft/lang/en_us.json @@ -5,5 +5,7 @@ "other.prefix.bar": "u1", "other.prefix.baz": "v1", "foo.hello": "1", - "foo.world": "4" + "foo.world": "4", + "entity.gm4.congealed_shard": "Congealed Soul Shard\u00a7", + "entity.gm4.fire_sprite": "Fire Sprite \"named bob\"" }