A Python package that converts Android & iOS strings files to any supported file type.
Report Bug · Request Feature · Ask Question
- About the Project
- Release Files
- Getting Started
- Usage
- Notes
- Roadmap
- Contributing
- License
- Authors
- Acknowledgments
- Support
I tried to do the whole process of converting a strings resource file into a spreadsheet in Google Sheets by hand and, even though you can do it with the option Data > Split text to columns, it involves wasting your time generating the spreadsheet manually. Due to that, I decided to build a time-efficient solution, which consists on running a Python script in order to achieve that with any file type.
Moreover, not only this script can be executed on its own, it also can be installed as a package via PyPI (more information here about how to install it).
- Android strings format (
*.xml
) - CSV
- Google Sheets support
- HTML
- iOS strings format (
*.strings
) - JSON
- MD
- ODS
- XLSX
- YAML
ASCII folder structure
│ .gitignore
│ .pre-commit-config.yaml
│ LICENSE
│ poetry.lock
│ pyproject.toml
│ README.md
│ requirements.txt
│ requirements-dev.txt
│
├───.github
│ │ CONTRIBUTING.md
│ │
│ ├───ISSUE_TEMPLATE
│ │ bug_report_template.md
│ │ feature_request_template.md
│ │
│ └───PULL_REQUEST_TEMPLATE
│ pull_request_template.md
│
├───docs
│ icon.png
│
├───src
│ ├───mobile_strings_converter
│ │ console_style.py
│ │ converter.py
│ │ __init__.py
│ │ __main__.py
│ │
│ ├───assets
│ │ └───fonts
│ │ Aakar.ttf
│ │ AnekTelugu-VariableFont_wdth,wght.ttf
│ │ DejaVuSansCondensed.ttf
│ │ Eunjin.ttf
│ │ fireflysung.ttf
│ │ gargi.ttf
│ │ Gurvetica_a8_Heavy.ttf
│ │ Latha.ttf
│ │ Waree.ttf
│ │
│ ├───controller
│ │ main_controller.py
│ │ __init__.py
│ │
│ ├───model
│ │ transcription.py
│ │ __init__.py
│ │
│ ├───utils
│ │ constants.py
│ │ i18n.py
│ │ path_helper.py
│ │ __init__.py
│ │
│ └───view
│ main_window.py
│ __init__.py
│
└───tests
│ base_tests.py
│ test_get_strings.py
│ test_to_android.py
│ test_to_csv.py
│ test_to_html.py
│ test_to_ios.py
│ test_to_json.py
│ test_to_md.py
│ test_to_ods.py
│ test_to_pdf.py
│ test_to_xlsx.py
│ test_to_yaml.py
│
└───files
├───input
│ Localizable.strings
│ strings.xml
│
├───template-with-comments
│ Localizable.strings
│ strings.csv
│ strings.html
│ strings.json
│ strings.md
│ strings.ods
│ strings.pdf
│ strings.xlsx
│ strings.xml
│ strings.yaml
│
└───template-without-comments
Localizable.strings
strings.csv
strings.html
strings.json
strings.md
strings.ods
strings.pdf
strings.xlsx
strings.xml
strings.yaml
- openpyxl to generate ODS and XLSX files.
- gspread to generate spreadsheets in Google Sheets.
- protobuf is used by
google.oauth2.credentials
to authenticate to the user's Google account in order to create the spreadsheet in Google Sheets. - PyYAML to generate YAML files.
- arabic-reshaper and python-bidi to add arabic characters support for PDF files.
- fpdf2 to generate PDF files.
- lingua-language-detector to recognize the value language when writing a PDF in order to know what font to use.
File | Description | Size |
---|---|---|
mobile-strings-converter.zip | Standard language support for PDF files (over 100 languages, including RTL) | 0.32 MB |
mobile-strings-converter-indic.zip | PDF file support for Indic languages (see list) | 1.40 MB |
mobile-strings-converter-zh-ja.zip | PDF file support for Japanese and Chinese (simplified and traditional) | 7.17 MB |
mobile-strings-converter-ko.zip | PDF file support for Korean | 0.46 MB |
mobile-strings-converter-th.zip | PDF file support for Thai | 0.37 MB |
mobile-strings-converter-all.zip | PDF file support for almost all languages (see exceptions) | 8.43 MB |
- Download the release that is best suited to your needs.
- (Optional but recommended) Create a Python virtual environment in the project root. If you're using
virtualenv
, you would runvirtualenv venv
. - (Optional but recommended) Activate the virtual environment:
# on Windows . venv/Scripts/activate # if you get the error `FullyQualifiedErrorId : UnauthorizedAccess`, run this: Set-ExecutionPolicy Unrestricted -Scope Process # and then . venv/Scripts/activate # on macOS and Linux source venv/Scripts/activate
- Open the command line and run
pip install -r path/to/requirements.txt
to install the required packages to run the script.
Install the PyPI package by running pip install mobile-strings-converter
.
For a basic usage, you can run the following command:
python path/to/mobile_strings_converter.py <*.xml | *.strings> -o <*.[SUPPORTED_FILE_TYPE]>
See Generate a Spreadsheet in Google Sheets to create a spreadsheet.
Once you have followed the steps indicated in the Getting Started section, you just have to use the convert_strings
function. Here is an example:
- Import the package and the wrapper function you wish to use
from mobile_strings_converter import [FUNCTION]
- Use it in your package like this:
# For example, using convert_strings function from mobile_strings_converter import convert_strings convert_strings( input_filepath=Path("strings.xml"), output_filepath=Path("strings-en.xlsx"), should_print_comments=True )
Before going further into running the commands to do so, please note that you will have to generate a service_account.json
file. You can do the following to get one:
- Go to the Google Cloud Console.
- Create a new project or select an existing project.
- Go to the APIs & Services page, click on Dashboard and then click on Enable APIs and Services.
- Search for Google Sheets API and enable it.
- Go to the Credentials page, click on Create credentials, and then choose Service account.
- Give your service account a name and select a role. For this purpose, you can select Project -> Editor.
- Click on the Create key button, select the JSON format and download the
service_account.json
file. - Share your Google Sheets file with the email address that is specified in the client_email field in the
service_account.json
file.
Alternatively, you can create a .xlsx
file and open it in Google Sheets if you do not want to go through the hassle of generating the service_account.json
file.
Once you have generated the service_account.json
file, you can generate a spreadsheet in Google Sheets by running the following command:
python path/to/mobile_strings_converter.py <*.xml | *.strings> -g <SHEET_NAME> -c path/to/service_account.json
If you want to generate an output file along with the spreadsheet, run this:
python path/to/mobile_strings_converter.py <*.xml | *.strings> -g <SHEET_NAME> -c path/to/service_account.json -o <*.SUPPORTED_FILE_TYPE>
from mobile_strings_converter import to_google_sheets
to_google_sheets(
input_filepath=Path("path/to/strings-file"),
sheet_name="MyProject strings",
credentials_filepath=Path("path/to/service_account.json"),
should_print_comments=True,
)
Flag | Description |
---|---|
-h or --help |
Displays help text for the program |
-o or --output-filepath |
Specifies the filepath for storing the converted file. The file extension can be chosen from the list of supported file types mentioned here. |
-g or --google-sheets |
Followed by the name of the sheet, creates a new Google Sheets spreadsheet with the specified name. |
-c or --credentials |
Followed by the path to your service_account.json file is mandatory if you want to generate a spreadsheet in your Google account. |
-p or --print-comments |
The output file will include any commented strings present in the original file. |
- Hindi
- Marathu
- Oriya
- Tibetan
- Gujarati
- Telugu
- Tamil
- Punjabi
- Bengali (not possible to print correctly using fpdf2)
- Dhivehi (not recognized by lingua-language-detector)
- Kannada (not recognized by lingua-language-detector)
- Khmer (not recognized by lingua-language-detector)
- Lao (not recognized by lingua-language-detector)
- Malayalam (not recognized by lingua-language-detector)
- Meiteilon (manipuri) (not recognized by lingua-language-detector)
- Myanmar burmese (not possible to print correctly using fpdf2)
- Odia (Oriya) (not recognized by lingua-language-detector)
- Sinhala (not recognized by lingua-language-detector)
- Tigrinya (not recognized by lingua-language-detector)
- Add support for multiple
.xml
/.strings
files input. - Add support for converting a file (not
.xml
nor.strings
) to a strings resource file. - Make a web version.
You can propose a new feature creating an issue.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. Please, read the CONTRIBUTING.md file, where you can find more detailed information about how to contribute to the project.
Distributed under the MIT License. See LICENSE
for more information.
- HenestrosaDev henestrosadev@gmail.com (José Carlos López Henestrosa)
See also the list of contributors who participated in this project.
I have made use of the following resources to make this project:
Would you like to support the project? That's very kind of you! You can go to my Ko-Fi profile by clicking on the button down below.