Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ty0x2333 committed Feb 7, 2017
2 parents b312473 + 2bc223f commit 2472a8e
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 91 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- The lines that are in the format of chaos is not processed.
3. cli add `--utf8` option

1.0.0
1.0.1
---
#### Feature
1. add `translate` subcommand
Expand All @@ -16,3 +16,16 @@
-o DESTINATIONS [DESTINATIONS ...]
```
2. tystrings as subcommand 'tystrings generate'

1.1.0
---
#### Bug Fixed
1. Parser Error [issue #1](https://github.com/luckytianyiyan/TyStrings/issues/1)
```
/* No comment provided by engineer. */
"parsing.test.4" ="Test4
Test4
Test4Test4Test4
Test4
";
```
59 changes: 40 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
strings file generation / translation tool for iOS
strings file tool for iOS / macOS developers

|pypi| |build| |coverage| |license|

|screenshot|

Installation
============

Expand All @@ -27,38 +29,53 @@ Usage
.. code-block:: bash
$ tystrings -h
usage: tystrings [-h] [--version] {generate,translate} ...
usage: tystrings [-h] [--version] {generate,translate,lint,diff} ...
_______ _____ _ _
|__ __| / ____| | (_)
| |_ _| (___ | |_ _ __ _ _ __ __ _ ___
| | | | |\___ \| __| '__| | '_ \ / _` / __|
| | |_| |____) | |_| | | | | | | (_| \__ \
|_|\__, |_____/ \__|_| |_|_| |_|\__, |___/
__/ | __/ |
|___/ |___/
_______ _____ _ _
|__ __| / ____| | (_)
| |_ _| (___ | |_ _ __ _ _ __ __ _ ___
| | | | |\___ \| __| '__| | '_ \ / _` / __|
| | |_| |____) | |_| | | | | | | (_| \__ \
|_|\__, |_____/ \__|_| |_|_| |_|\__, |___/
__/ | __/ |
|___/ |___/
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-h, --help show this help message and exit
--version show program's version number and exit
subcommands:
{generate,translate}
generate generate `.strings` file from source code files.
translate using Baidu Translate Service to translate `.strings` file.
{generate,translate,lint,diff}
generate generate `.strings` file from source code files.
translate using Baidu Translate Service to translate `.strings`
file.
lint Validates a `.strings` file.
diff Compare `.strings` files line by line.
To run `tystrings generate` over all .m files in your project, you can invoke it, for example, like this:
.. code-block:: bash
$ tystrings generate $(find . -name \*.m) -o en.lproj zh-Hans.lprog -v
To run tystrings over all .m files in your project, you can invoke it, for example, like this:
translate `.strings` file to another language:
.. code-block:: bash
tystrings generate $(find . -name \*.m) -o en.lproj zh.lprog -v
$ tystrings translate en.lproj/Localizable.strings zh-Hans.lproj/Localizable.strings --src-lang en --dst-lang zh
translate .strings file to another language:
validates `.strings` file:
.. code-block:: bash
tystrings translate en.lproj/Localizable.strings zh-Hans.lproj/Localizable.strings --src-lang en --dst-lang zh
$ tystrings lint en.lproj/Localizable.strings
compare two `.strings` files:
.. code-block:: bash
$ tystrings diff Localizable1.strings Localizable2.strings
.. |pypi| image:: https://img.shields.io/pypi/v/TyStrings.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/TyStrings
Expand All @@ -75,3 +92,7 @@ translate .strings file to another language:
.. |coverage| image:: https://coveralls.io/repos/github/luckytianyiyan/TyStrings/badge.svg
:target: https://coveralls.io/github/luckytianyiyan/TyStrings
:alt: Coverage Testing Results
.. |screenshot| image:: resource/tystrings.gif
:target: resource/tystrings.gif
:alt: TyStrings Screenshot
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coveralls==1.1
docopt==0.6.2
nose==1.3.7
requests==2.11.0
tabulate==0.7.7
Binary file added resource/recording
Binary file not shown.
Binary file added resource/tystrings.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added script/tystrings.scpt
Binary file not shown.
17 changes: 14 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@
# To use a consistent encoding
from codecs import open
from os import path
import sys
import subprocess
import re

here = path.abspath(path.dirname(__file__))
if not sys.platform == 'darwin':
sys.exit("Sorry, %s is not supported (yet)" % sys.platform)

try:
subprocess.call(['genstrings'])
except OSError:
sys.exit("require genstrings \n"
"https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/genstrings.1.html"
)

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'tystrings/version.py'), encoding='utf8') as version_file:
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read(), re.M)
Expand All @@ -37,7 +48,7 @@
# https://packaging.python.org/en/latest/single_source_version.html
version=version,

description='strings file generation / translation tool for iOS',
description='strings file tool for iOS / macOS developers',
long_description=long_description,

# The project's main homepage.
Expand Down Expand Up @@ -91,7 +102,7 @@
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['colorama>=0.3.7', 'requests>=2.11.0'],
install_requires=['colorama>=0.3.7', 'requests>=2.11.0', 'tabulate>=0.7.7'],

# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
Expand Down
Binary file modified tests/example/strings/base.strings
Binary file not shown.
Binary file modified tests/example/strings/comment.strings
Binary file not shown.
Binary file added tests/example/strings/diff1.strings
Binary file not shown.
Binary file added tests/example/strings/diff2.strings
Binary file not shown.
Binary file added tests/example/strings/lint.strings
Binary file not shown.
Binary file modified tests/example/strings/space.strings
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/example/strings/utf8.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* No comment provided by engineer. */
"generate.reference.test.0" = "Test0";
"parsing.test.0" = "Test0";

/* No comment provided by engineer. */
"generate.reference.test.1" = "Test1";
"parsing.test.1" = "Test1";
95 changes: 95 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import unittest
import sys
import tempfile
import subprocess
import os
from shutil import rmtree
from tystrings import cli


class CLIBaseTest(unittest.TestCase):
def setUp(self):
self.temp_path = tempfile.mkdtemp()
self.cwd = self.temp_path

def tearDown(self):
rmtree(self.temp_path)

def call(self, *new_args, **kwargs):
pass

def test_base(self):
self.assertEqual(0, self.call('-h'))
self.assertEqual(0, self.call('--version'))

def test_diff(self):
subcommand = 'diff'
self.assertEqual(0, self.call(subcommand, '-h'))

file1 = os.path.abspath('tests/example/strings/diff1.strings')
file2 = os.path.abspath('tests/example/strings/diff2.strings')
self.assertEqual(0, self.call(subcommand, file1, file2, '-v'))

def test_lint(self):
subcommand = 'lint'
self.assertEqual(0, self.call(subcommand, '-h'))

dst = os.path.abspath('tests/example/strings/lint.strings')
self.assertEqual(1, self.call(subcommand, dst, '-v'))

dst = os.path.abspath('tests/example/strings/base.strings')
self.assertEqual(0, self.call(subcommand, dst, '-v'))

def test_translate(self):
subcommand = 'translate'
self.assertEqual(0, self.call(subcommand, '-h'))

src = os.path.abspath('tests/example/strings/base_translator.strings')
dst = os.path.join(self.cwd, 'base_translator.strings')
dst_lang = 'zh'
src_lang = 'en'

self.assertEqual(0, self.call(subcommand, src, dst, '--dst-lang', dst_lang, '--src-lang', src_lang))
self.assertTrue(os.path.exists(dst))
os.remove(dst)

self.assertEqual(0, self.call(subcommand, src, dst, '--dst-lang', dst_lang))
self.assertTrue(os.path.exists(dst))

def test_generate(self):
subcommand = 'generate'
self.assertEqual(0, self.call(subcommand, '-h'))

src = os.path.abspath('tests/example/IntegrationDemo.m')
dst = os.path.join(self.cwd, 'generate')

# input directory
self.assertEqual(2, self.call(subcommand, self.cwd, '-o', dst))
# file not exists
self.assertEqual(2, self.call(subcommand, 'xxxxxxx', '-o', dst))

generated_path = os.path.join(dst, 'Localizable.strings')
self.assertEqual(0, self.call(subcommand, src, '-o', dst))
self.assertTrue(os.path.exists(generated_path))
rmtree(dst)

self.assertEqual(0, self.call(subcommand, src, '-o', dst, '--utf8'))
self.assertTrue(os.path.exists(generated_path))


# class CLITests(CLIBaseTest):
# def call(self, *new_args, **kwargs):
# with tempfile.TemporaryFile() as out:
# args = (sys.executable, '-m', 'tystrings.cli') + new_args
# return subprocess.call(args, stdout=out, stderr=out, cwd=self.cwd, **kwargs)
# # return subprocess.call(args, cwd=self.cwd, **kwargs)


class CLIWhiteTests(CLIBaseTest):
def call(self, *new_args, **kwargs):
with self.assertRaises(BaseException) as cm:
cli.main(list(new_args))
return cm.exception.code

# ignore base class
del(CLIBaseTest)
32 changes: 0 additions & 32 deletions tests/test_generate_reference.py

This file was deleted.

34 changes: 34 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from tystrings import *


class ParsingTest(unittest.TestCase):
def setUp(self):
self.strings = Strings()

def test_base(self):
result = Strings.parsing('tests/example/strings/base.strings')
self.assertDictEqual(result, self._result(2))

def test_utf8(self):
result = Strings.parsing('tests/example/strings/utf8.strings', encoding='utf8')
self.assertDictEqual(result, self._result(2))

def test_comment(self):
result = Strings.parsing('tests/example/strings/comment.strings')
self.assertDictEqual(result, self._result(3))

def test_space(self):
result = Strings.parsing('tests/example/strings/space.strings')
right_answer = self._result(4)
right_answer['parsing.test.4'] = 'Test4\nTest4\nTest4Test4Test4\nTest4\n'
self.assertDictEqual(result, right_answer)

@staticmethod
def _result(count):
result = {}

for i in range(0, count):
result['parsing.test.%s' % i] = 'Test%s' % i

return result

0 comments on commit 2472a8e

Please sign in to comment.