GithubHelp home page GithubHelp logo

ocworld / pyxstr2swift Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 59 KB

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

License: MIT License

Makefile 1.15% Python 97.79% Swift 1.06%
python swift xcode ios macos strings codegenerator

pyxstr2swift's Introduction

pyxstr2swift

PyPI version shields.io PyPI pyversions MIT license

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

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

foo@bar:~$ pip install -U pyxstr2swift
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.
foo@bar:~$ brew install python
foo@bar:~$ pip3 install --upgrade pyxstr2swift

or

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

  1. Add a output swift file to your project
  2. Add a strings file to your project and write string keys and values
  3. Add Run Script to build pharses before Compile Sources
  4. Change Shell /bin/sh to /bin/bash (or /bin/zsh)
  5. Write shell command. For example,
#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_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
  1. That' all! build Your project now!
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

pyxstr2swift's People

Contributors

ocworld avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyxstr2swift's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.