Skip to main content

Python package for a xcode strings file to a swift localized string file

Project description

Copyright (c) 2018 Keunhyun Oh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project-URL: Bug Reports, https://github.com/ocworld/pyxstr2swift/issues
Project-URL: Source, https://github.com/ocworld/pyxstr2swift
Description: # pyxstr2swift

[![PyPI version shields.io](https://img.shields.io/pypi/v/ansicolortags.svg)](https://pypi.org/project/pyxstr2swift/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/ansicolortags.svg)](https://pypi.org/project/pyxstr2swift/)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)

## Description

Python package for a Xcode strings file to a swift localized string file

For example,

```
/*
Localizable.strings

Created by Keunhyun Oh on 2018. 8. 15..
Copyright © 2018년 Keunhyun Oh. All rights reserved.
*/

test = "test_value";

```

to

```swift
import Foundation

struct Localizable {
static let test = NSLocalizedString("test", tableName: "Localizable", comment: "") // test_value
}

```

It is available in python2.7, 3.4, 3.5, 3.6, and 3.7

```bash
foo@bar:~$ pip install -U pyxstr2swift
```

```bash
foo@bar:~$ xstr2swift [-h] [--st STRUCTNAME] [-f] [-m] [-v] source target
foo@bar:~$ python -m pyxstr2swift.xstr2swift [-h] [--structname STRUCTNAME] [-f] [-m] source target
```


To use it in Xcode build pharses,
1. Install this module using python PIP.
If pip is not installed on your device, this command helps you.

```bash
foo@bar:~$ brew install python
foo@bar:~$ pip3 install --upgrade pyxstr2swift
```

or

install anaconda and set configures
https://www.anaconda.com/download/

2. Add a output swift file to your project
3. Add a strings file to your project and write string keys and values
4. Add Run Script to build pharses before Compile Sources
5. Change Shell /bin/sh to /bin/bash (or /bin/zsh)
6. Write shell command.
For example,
```bash
#If you use anaconda, anaconda3/bin should be added to path
#export PATH="${HOME}/anaconda3/bin:$PATH"
pip install --upgrade pyxstr2swift
xstr2swift -f -m "${SRCROOT}/Your project/en.lproj/Localizable.strings" "${SRCROOT}/Your project/Localizable.swift"
```

My project's shell command is that
```bash
# .bash_profile includes export PATH="${HOME}/anaconda3/bin:$PATH"
source ~/.bash_profile

# a conda env is already created that name is iosdev
conda activate iosdev
pip install --upgrade pyxstr2swift
xstr2swift -f -m "${SRCROOT}/My Project/en.lproj/Localizable.strings" "${SRCROOT}/My Project/Localizable.swift"
conda deactivate
```

7. That' all! build Your project now!

```bash
usage: xstr2swift [-h] [-st STRUCTNAME] [-f] [-m] [-v] source target

pyxstr2swift needs arguments

positional arguments:
source source: a strings file
target target: a swift file

optional arguments:
-h, --help show this help message and exit
-st STRUCTNAME, --structname STRUCTNAME
structname: a struct name in a target file
-f, --force force to write a target file if already exist
-m, --comment values are added as comment
-v, --verbose Display console output
```

## Test
unittest on python 2.7, 3.4, 3.5, 3.6, 3.7

## References
- https://medium.com/ios-forever/ios에서-localization하는-gorgeous-한-방법-f82ac29d2cfe
Thanks to an author of this post
- https://github.com/ocworld/OHSwiftLocalizedString
It is help you to use localized strings

Platform: any
Classifier: Topic :: Software Development :: Code Generators
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.4
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Developers
Classifier: Environment :: MacOS X
Classifier: Programming Language :: Python :: 3.6
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Programming Language :: Python :: 3.7

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

pyxstr2swift-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

pyxstr2swift-0.1.0-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyxstr2swift-0.1.0.tar.gz.

File metadata

  • Download URL: pyxstr2swift-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for pyxstr2swift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 992dadd06290cecd08363e768642cc5c9083a80d22ab98da3777ece733c0d25d
MD5 3e077de4a747d144684e1495aef9fa71
BLAKE2b-256 68cafc10e8f464ccec5298b3017f8c48ba4b17e56f47b743fa552ab0bfbed27a

See more details on using hashes here.

File details

Details for the file pyxstr2swift-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pyxstr2swift-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for pyxstr2swift-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9ab1ad382127f1abd788f955894972f769ea7e81bdb0341f88f6a43748e8dc21
MD5 a9ccb4a0ba2779f7438fa20872fdef09
BLAKE2b-256 16c86f8fe518daacdbb4daae2a236020d976b97207f253e5db830b9f6ffd9633

See more details on using hashes here.

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