/mobile-strings-converter

Convert Android & iOS string files to any supported file type, and vice versa.

Primary LanguagePythonMIT LicenseMIT


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

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

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)

Getting Started

To Download the Program

  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.

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)

Usage

To Run the Program

Run the program

python path/to/mobile_strings_converter.py <*.xml | *.strings> -o <*.SUPPORTED FILE TYPE EXTENSION>

To Use the Package in Your Project

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:

convert_strings(
    input_filepath=Path("strings.xml"), 
    output_filepath=Path("strings-en.xlsx"), 
    should_print_comments=True
)

To Generate a Spreadsheet in Google Sheets

Running the program

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:

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 EXTENSION>

Using the Package in Your Project

If you are using the package in your project, here is an example of how to use the to_google_sheets function:

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,
)

Script flags

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.

(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)