Skip to content

fix: correct XML encoding declaration in .strings files - #1205

Open
webkubor wants to merge 1 commit into
rime:masterfrom
webkubor:fix/strings-encoding-declaration
Open

webkubor wants to merge 1 commit into
rime:masterfrom
webkubor:fix/strings-encoding-declaration

Conversation

@webkubor

Copy link
Copy Markdown

Problem

The localized bundle names (鼠须管 / 鼠鬚管) are not displayed in the input menu. Instead, the English name "Squirrel" always appears.

Root Cause

Xcode 26.5 compiles String Catalogs (.xcstrings) into .strings files with UTF-16LE byte encoding, but the XML declaration incorrectly claims UTF-8:

<?xml version="1.0" encoding="UTF-8"?>

This mismatch causes macOS to fail parsing the files, falling back to the default (English) bundle name.

Evidence (extracted from official Squirrel-1.1.2.pkg):

$ file zh-Hans.lproj/InfoPlist.strings
zh-Hans.lproj/InfoPlist.strings: XML 1.0 document, UTF-16 Little Endian code unit, ...

$ head -c 100 zh-Hans.lproj/InfoPlist.strings | xxd
00000000: fffe 3c00 3f00 7800 6d00 6c00 2000 7600  ..<.?.x.m.l. .v.
00000010: 6500 7200 7300 6900 6f00 6e00 3d00 2200  e.r.s.i.o.n.=.".
00000020: 3100 2e00 3000 2200 2000 6500 6e00 6300  1.0.". .e.n.c.
00000030: 6f00 6400 6900 6e00 6700 3d00 2200 5500  o.d.i.n.g.=.".U.
00000040: 5400 4600 2d00 3800 2200 3f00 3e00      T.F.-.8.".?.>.

The file is clearly UTF-16LE (BOM: ff fe), but declares UTF-8.

Solution

This PR adds a build-time fix in package/make_package:

  1. package/fix_strings_encoding.py - A Python script that scans all .strings files in the build output and corrects the XML declaration to match the actual byte encoding (UTF-16)
  2. Modified package/make_package - Invokes the fix script before building the pkg

The fix is minimal, non-invasive, and only affects the build process.

Testing

Verified on macOS 26.5.2 with Xcode 26.5:

  • Before fix: Input menu shows "Squirrel" (English)
  • After fix: Input menu shows "鼠须管" (Chinese)

Related Issue

Fixes #1204

Xcode 26.5 compiles String Catalogs (.xcstrings) into .strings files with
UTF-16LE byte encoding, but the XML declaration incorrectly claims UTF-8.
This causes macOS to fail parsing them, falling back to English bundle names.

The fix adds a Python script that scans the build output and corrects the
XML declaration to match the actual byte encoding (UTF-16). The script is
invoked during the package build step.

Fixes: localized bundle names (e.g. 鼠须管) not appearing in input menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XML encoding declaration mismatch in .strings files causes localized names to fail

1 participant