Skip to main content

Quick Start

Install

pip3 install gslocalizator

Using

#!/usr/bin/env python
from gslocalizator import GoogleSheetLocalizator as GSLr
from cfg import *


def main():
    with GSLr(GSL_CREDS_FILE, GSL_SPREADSHEET_ID) as gslr:
        gslr.tran(
            from_sheet_range='main!A1:E',
            with_key_column='iOS(IM)Key',
            from_value_column_to_file={
                'zh-Hans': '.datas/ios/strings_main/zh-Hans.lproj/Localizable.strings',
                'zh-Hant': '.datas/ios/strings_main/zh-Hant.lproj/Localizable.strings',
                'en': '.datas/ios/strings_main/en.lproj/Localizable.strings',
                'ja': '.datas/ios/strings_main/ja.lproj/Localizable.strings',
            },
            exclude_headers=['//']
        ).request(
        ).save(format="iOS")


if __name__ == '__main__':
    main()

cell formater

Cell formater used to format cells in the spreadsheet.

for example:

title of key title of lang1 title of lang2 ...
Hello Hello 您好 hhhh
world world 世界 wwww

key_formater only be used to cells that under "title of key".

key_formater area

You can custom your formater for keys and cells

def cell_fmter(val: str) -> str:
    return re.sub("\s+", " ", val).strip().replace("%s", "%@").replace("\"", "\\\"")


def key_fmter(val: str) -> str:
    return re.sub("\s+", " ", val).strip().replace("%s", "%@")


def load():
    # ...
    with GSLr(GSL_CREDS_FILE, GSL_SPREADSHEET_ID) as gslr:
        gslr.tran(
            from_sheet_range='bizA!A1:F',
            with_key_column='key',
            from_value_column_to_file={
                'zh-Hans': '.datas/ios/strings_biz_a/zh-Hans.lproj/Localizable.strings',
                'zh-Hant': '.datas/ios/strings_biz_a/zh-Hant.lproj/Localizable.strings',
                'en': '.datas/ios/strings_biz_a/en.lproj/Localizable.strings',
                'ja': '.datas/ios/strings_biz_a/ja.lproj/Localizable.strings',
            },
            exclude_headers=['//'],
            cell_formater=cell_fmter
        ).request(
        ).save(format="iOS")
    # ...
# replace "'" to "\'" demo
def cell_fmter(val: str) -> str:
    aVal = re.sub('\w(\')', lambda x: x.group(1), val) # replace "'" to "\'"
    return re.sub("\s+", " ", aVal).strip().replace("%s", "%@").replace("\"", "\\\"")

You can merge diffrent sheets to one file.

Sheet "bizA" and sheet "main" merge to "app/***/strings.xml"

def request_android(gslr: GSLr):
    gslr.reset()
    gslr.tran(
        from_sheet_range='bizA!A1:E',
        with_key_column='key',
        from_value_column_to_file={
            'zh-Hans': '.datas/android/app/values-zh-rCN/strings.xml',
            'zh-Hant': '.datas/android/app/values-zh-rTWj/strings.xml',
            'en': '.datas/android/app/values/strings.xml',
            'ja': '.datas/android/app/values-ja-rJP/strings.xml',
        },
        exclude_headers=['//'],
        cell_formater=cell_fmter,
        key_formater=key_fmter
    ).tran(
        from_sheet_range='main!A1:E',
        with_key_column='iOS(IM)Key',
        from_value_column_to_file={
            'zh-Hans': '.datas/android/app/values-zh-rCN/strings.xml',
            'zh-Hant': '.datas/android/app/values-zh-rTWj/strings.xml',
            'en': '.datas/android/app/values/strings.xml',
            'ja': '.datas/android/app/values-ja-rJP/strings.xml',
        },
        exclude_headers=['//']
    ).request(
    ).save(format="Android")

Or you can write diff sheets to their own files.

Sheet "bizA" save to "strings_biz_a/***/strings.xml"

Sheet "main" save to "strings_main/***/strings.xml"

def request_android(gslr: GSLr):
    gslr.reset()
    gslr.tran(
        from_sheet_range='bizA!A1:E',
        with_key_column='key',
        from_value_column_to_file={
            'zh-Hans': '.datas/android/strings_biz_a/values-zh-rCN/strings.xml',
            'zh-Hant': '.datas/android/strings_biz_a/values-zh-rTWj/strings.xml',
            'en': '.datas/android/strings_biz_a/values/strings.xml',
            'ja': '.datas/android/strings_biz_a/values-ja-rJP/strings.xml',
        },
        exclude_headers=['//'],
        cell_formater=cell_fmter,
        key_formater=key_fmter
    ).tran(
        from_sheet_range='main!A1:E',
        with_key_column='iOS(IM)Key',
        from_value_column_to_file={
            'zh-Hans': '.datas/android/strings_main/values-zh-rCN/strings.xml',
            'zh-Hant': '.datas/android/strings_main/values-zh-rTWj/strings.xml',
            'en': '.datas/android/strings_main/values/strings.xml',
            'ja': '.datas/android/strings_main/values-ja-rJP/strings.xml',
        },
        exclude_headers=['//']
    ).request(
    ).save(format="Android")

Metadata

Release files for gslocalizator 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gslocalizator 1.0.0
File Size Uploaded Provenance Actions
gslocalizator-1.0.0.tar.gz 8.2 kB Without provenance Details for gslocalizator-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gslocalizator 1.0.0
File Interpreter ABI Platform Actions
gslocalizator-1.0.0-py3-none-any.whl Python 3 none any Details for gslocalizator-1.0.0-py3-none-any.whl

Total release size: 16.4 kB

Release files / gslocalizator-1.0.0.tar.gz

Download URL gslocalizator-1.0.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ed5aec2918daca65876afb4425ec15b61810e7f690b817809670f6b0a512f05c
BLAKE2b-256 checksum
How to use checksums
d252a37aeafbaed1cd72e8d798df5150a290445b79334cbfd339f5538b4d8382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Release files / gslocalizator-1.0.0-py3-none-any.whl

Download URL gslocalizator-1.0.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dc77a3032b6447f7a69a6c188602ee1106afee0607d6cbca3108973eccf58ce
BLAKE2b-256 checksum
How to use checksums
d61f95f0cc13af288f36963fc29238141780136fe93f9e4ae9715faca9c02aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Security for gslocalizator 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page