Skip to main content

A Python package that converts Android & iOS strings files to any supported file type.

Project description


Logo

Mobile strings converter

A Python package that converts Android & iOS strings files to any supported file type.

PyPI version Python versions support
GitHub action: Build Codecov License
GitHub Contributors Issues GitHub pull requests

Report Bug · Request Feature · Ask Question

Table of Contents

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
  • PDF
  • XLSX
  • YAML

Project Structure

Root directories:

  • .github/workflows: GitHub workflows. It also includes the templates for issues and pull requests, as well as the depandabot.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 the files 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, execute pip 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, execute pip 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.

(back to top)

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

(back to top)

Usage

To Execute The Script

  1. Download the release that is best suited to your needs.
  2. Open the command line and run pip install -r path/to/requirements.txt to install the required packages to execute the script.
  3. 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:

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing project.
  3. Go to the APIs & Services page, click on Dashboard and then click on Enable APIs and Services.
  4. Search for Google Sheets API and enable it.
  5. Go to the Credentials page, click on Create credentials, and then choose Service account.
  6. Give your service account a name and select a role. For this purpose, you can select Project -> Editor.
  7. Click on the Create key button, select the JSON format and download the service_account.json file.
  8. 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

  1. Run pip install mobile-strings-converter
  2. Import the package and the wrapper function with this line of code: from mobile_strings_converter import convert_strings.

To Open the Code

  1. Clone the project with the git clone https://github.com/HenestrosaConH/mobile-strings-converter.git command.
  2. Open it in your favourite IDE (mine is PyCharm)

(back to top)

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

(back to top)

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.

(back to top)

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.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Authors

See also the list of contributors who participated in this project.

(back to top)

Acknowledgments

I have made use of the following resources to make this project:

(back to top)

Support

ko-fi

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobile_strings_converter-0.1.1.tar.gz (8.7 MB view hashes)

Uploaded Source

Built Distribution

mobile_strings_converter-0.1.1-py3-none-any.whl (8.7 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page