A Python package that converts Android & iOS strings files to any supported file type.
Project description
Mobile strings converter
A Python package that converts Android & iOS strings files to any supported file type.
Report Bug · Request Feature · Ask Question
Table of Contents
- About the Project
- Release Files
- Usage
- Notes
- Roadmap
- Contributing
- License
- Authors
- Acknowledgments
- Support
About the Project
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).
The file types supported by the package are the following:
- Android strings format (
*.xml
) - CSV
- Google Sheets support
- HTML
- iOS strings format (
*.strings
) - JSON
- MD
- ODS
- XLSX
- YAML
Project Structure
Root directories:
.github/workflows
: GitHub workflows. It also includes the templates for issues and pull requests, as well as thedepandabot.yml
file for Dependabot configuration.docs
: Contains files related to the documentation of the project.src/mobile_strings_converter
: Contains the source code files.tests
: Contains unit tests to ensure the correct functionality of the package. It also includes thefiles
directory, which contains a few demo files in different formats to use in the unit tests.
Root files:
.gitignore
: File used by the version control system Git to specify files or directories that should be ignored by Git when tracking changes to a project..pre-commit-config.yaml
: Configuration file used by pre-commit, a tool that runs checks (such as linting, testing, or formatting) on the code before you commit changes to version control. The file specifies which checks pre-commit should run and how it should run them.LICENSE
: Project license, which is MIT.poetry.lock
: File generated by Poetry, a package manager for Python, that contains the exact versions of all packages used by a project. The file is used to ensure that all members of a development team are using the same versions of packages, even if different versions are available in the package repository.pyproject.toml
: Configuration file used by Poetry. It specifies the metadata for a Python project, including the project name, version, description, author, license and dependencies.README.md
: What you are reading right now.requirements.txt
: Lists the names and versions of each package used to build this project. To install the requirements, executepip install -r requirements.txt
.requirements-dev.txt
: Lists the names and versions of each package used in the development stage of this project. To install the requirements, executepip install -r requirements-dev.txt
.
Built With
- openpyxl: To generate ODS and XLSX files.
- gspread: To generate spreadsheets in Google Sheets.
- protobuf: 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.
Release Files
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 |
Usage
To Execute The Script
- Download the release that is best suited to your needs.
- Open the command line and run
pip install -r path/to/requirements.txt
to install the required packages to execute the script. - Example of a basic command to convert a
.xml
or.strings
file to another file type:path/to/python path/to/mobile_strings_converter.py path/to/<*.xml | *.strings> -o path/to/*.<SUPPORTED FILE TYPE EXTENSION>
To Generate a Spreadsheet in Google Sheets
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 an 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:
path/to/python path/to/mobile_strings_converter.py path/to/<strings.xml | Localizable.strings> -gs <SHEET NAME> -c path/to/service_account.json
If you want to generate an output file along with the spreadsheet, run this:
path/to/python path/to/mobile_strings_converter.py path/to/<strings.xml | Localizable.strings> -gs <SHEET NAME> -c path/to/service_account.json -o path/to/strings.<SUPPORTED FILE TYPE EXTENSION>
Script flags
-h
,--help
: Show help-o
,--output-filepath
: Output filepath where you want to store the converted file. Its extension can be any of the file types listed here.-g
,--google-sheets
: Creates a spreadsheet in Google Sheets with the name passed as argument.-c
,--credentials
<service_account.json
filepath>: Mandatory if you want to generate a spreadsheet in your Google account.-p
,--print-comments
: If present, indicates that commented strings will be printed in the output file.
To Import the Package Into Your Project
- Run
pip install mobile-strings-converter
- Import the package and the wrapper function with this line of code:
from mobile_strings_converter import convert_strings
.
To Open the Code
- Clone the project with the
git clone https://github.com/HenestrosaConH/mobile-strings-converter.git
command. - Open it in your favourite IDE (mine is PyCharm)
Notes
List of Indic Languages Supported by PDF files
- Hindi
- Marathu
- Oriya
- Tibetan
- Gujarati
- Telugu
- Tamil
- Punjabi
List of Languages Not Supported by PDF files
- 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)
Roadmap
- 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.
Contributing
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.
License
Distributed under the MIT License. See LICENSE
for more information.
Authors
- HenestrosaConH henestrosaconh@gmail.com (José Carlos López Henestrosa)
See also the list of contributors who participated in this project.
Acknowledgments
I have made use of the following resources to make this project:
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mobile_strings_converter-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e69d4794d6097fe4a7814000ae4ff8cc092282742de3acd462f724380a55ec |
|
MD5 | 4c6bfe6f8f56e38e7b22097f49401dfd |
|
BLAKE2b-256 | 14a437d6b50535292b5e90a721dd75b23d9277afb41da6528d72851b270b8e78 |
Hashes for mobile_strings_converter-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfe0ba0213331d7bef31387fa0b1599b2543c150181468212a7ab1da6c32dd63 |
|
MD5 | 281c09b6f58c311cc94117f8f6c94e8d |
|
BLAKE2b-256 | 3f9f8742e478c1a72ae895747ae3cc805ae999bce3d75a4a10bbbce8a2d487e2 |