Convert Excel file (.xlsx format) containing internationalization (i18n) data into JSON format.
Input: .xlsx file with the following format:
-
Sheet names:
- Representing main grouped component (e.g., UI component).
- The grouped component can be written in any case, following the developer convention.
- Example:
COMMONBUTTON
-
Content:
keycolumns representing unique identifier of each translation string for each supported language code and region.- Each
keycan be written in any case, following the developwer convention.- Example:
Apply
- Example:
- If there are any keys used for managing sub group, the child key corresponding to the parent key should be separated with
.(dot) notation.- Example:
Confirm.YesConfirm.No
- Example:
-
Example:
A sheet named
COMMONBUTTONhas the following data:key zh-TW en-US Apply 套用 Apply Export 道出 Export Send 送出 Send Confirm.Yes 是 Yes Confirm.No 否 No
Output:
-
Individual JSON files, named according to their language code and region (e.g.,
en-US.json,zh-TW.json, etc.), are stored within a directory named with the date and time of generation inside thei18n-outputdirectory. The date-time format for the directory name isYYYYMMDD-HHmm.Example:
i18n-xlsx-to-json/ ├── i18n-output/ │ └── 20250212-1500/ │ ├── en-US.json │ └── zh-TW.json
-
zh-TWJSON file sample output:{ "COMMONBUTTON": { "Apply": "套用", "Export": "道出", "Send": "送出", "Confirm": { "Yes": "是", "No": "否" } } } -
en-USJSON file sample output:{ "COMMONBUTTON": { "Apply": "Apply", "Export": "Export", "Send": "Send", "Confirm": { "Yes": "Yes", "No": "No" } } }
Change your directory into this workspace directory, then install the requirements.
pip install -r requirements.txtPlace the multi-language Excel file (e.g., i18n.xlsx) under the workspace directory as described on the following example:
i18n-xlsx-to-json/
└── i18n.xlsxMake sure the i18n Excel file name on the xlsx-to-json.py script is matched to the file placed under the workspace directory.
# Load the Excel file
xlsx = pd.read_excel('i18n.xlsx', sheet_name=None)Execute the Python script using the following command:
python xlsx-to-json.pyEach JSON files output, named according to their language code and region (e.g., en-US.json, zh-TW.json, etc.), are stored within a directory named with the date and time of generation inside the i18n-output directory. The date-time format for the directory name is YYYYMMDD-HHmm.
i18n-xlsx-to-json/
├── i18n-output/
│ └── 20250212-1500/
│ ├── en-US.json
│ └── zh-TW.json