Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2018-03-30 15:04:35 +0300
committerAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2018-03-30 15:43:36 +0300
commitb88c69bc6199f46794a0b16a01bc3c6e9f05ad4c (patch)
treeea193249f9c61278fae0b6bafe89ae43716f73ed /tools
parentc2c4ab62542c5e58b5580899d8d0c731395ce219 (diff)
[twine] Make twine a submodule, and update it to 1.0.3
Diffstat (limited to 'tools')
m---------tools/twine0
-rw-r--r--tools/twine/.gitignore3
-rw-r--r--tools/twine/0.10.1.patch31
-rw-r--r--tools/twine/Gemfile2
-rw-r--r--tools/twine/LICENSE30
-rw-r--r--tools/twine/README.md232
-rw-r--r--tools/twine/Rakefile8
-rwxr-xr-xtools/twine/bin/twine7
-rw-r--r--tools/twine/lib/twine.rb41
-rw-r--r--tools/twine/lib/twine/cli.rb409
-rw-r--r--tools/twine/lib/twine/encoding.rb22
-rw-r--r--tools/twine/lib/twine/formatters.rb20
-rw-r--r--tools/twine/lib/twine/formatters/abstract.rb163
-rw-r--r--tools/twine/lib/twine/formatters/android.rb158
-rw-r--r--tools/twine/lib/twine/formatters/apple.rb91
-rw-r--r--tools/twine/lib/twine/formatters/django.rb103
-rw-r--r--tools/twine/lib/twine/formatters/flash.rb72
-rw-r--r--tools/twine/lib/twine/formatters/gettext.rb105
-rw-r--r--tools/twine/lib/twine/formatters/jquery.rb79
-rw-r--r--tools/twine/lib/twine/formatters/tizen.rb137
-rw-r--r--tools/twine/lib/twine/output_processor.rb57
-rw-r--r--tools/twine/lib/twine/placeholders.rb74
-rw-r--r--tools/twine/lib/twine/plugin.rb62
-rw-r--r--tools/twine/lib/twine/runner.rb325
-rw-r--r--tools/twine/lib/twine/stringsfile.rb201
-rw-r--r--tools/twine/lib/twine/twine_file.rb229
-rw-r--r--tools/twine/lib/twine/version.rb3
-rwxr-xr-xtools/twine/twine3
-rw-r--r--tools/twine/twine.gemspec34
29 files changed, 0 insertions, 2701 deletions
diff --git a/tools/twine b/tools/twine
new file mode 160000
+Subproject 1813945b2d0d05a75acb328c8ffbe28b70d41ae
diff --git a/tools/twine/.gitignore b/tools/twine/.gitignore
deleted file mode 100644
index 0012a3255d..0000000000
--- a/tools/twine/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.gem
-.idea/
-*.lock
diff --git a/tools/twine/0.10.1.patch b/tools/twine/0.10.1.patch
deleted file mode 100644
index 643c45dad2..0000000000
--- a/tools/twine/0.10.1.patch
+++ /dev/null
@@ -1,31 +0,0 @@
-diff -r twine-0.10.1/lib/twine/formatters/android.rb twine/lib/twine/formatters/android.rb
-9a10,17
-> LANG_CODES = Hash[
-> 'zh' => 'zh-Hans',
-> 'zh-CN' => 'zh-Hans',
-> 'zh-HK' => 'zh-Hant',
-> 'en-GB' => 'en-GB',
-> 'in' => 'id'
-> ]
->
-36c44,47
-< return match[1].sub('-r', '-') if match
----
-> if match
-> lang = match[1].sub('-r', '-')
-> return LANG_CODES.fetch(lang, lang)
-> end
-diff -r twine-0.10.1/lib/twine/formatters/jquery.rb twine/lib/twine/formatters/jquery.rb
-19c19
-< match = /^((.+)-)?([^-]+)\.json$/.match(segment)
----
-> match = /^(.+)\.json$/.match(segment)
-21c21
-< return match[3]
----
-> return match[1]
-diff -r twine-0.10.1/lib/twine/placeholders.rb twine/lib/twine/placeholders.rb
-8c8
-< PLACEHOLDER_TYPES = '[diufFeEgGxXoscpaA]'
----
-> PLACEHOLDER_TYPES = '[diufFeEgGxXoscpaAq]'
diff --git a/tools/twine/Gemfile b/tools/twine/Gemfile
deleted file mode 100644
index 3be9c3cd81..0000000000
--- a/tools/twine/Gemfile
+++ /dev/null
@@ -1,2 +0,0 @@
-source "https://rubygems.org"
-gemspec
diff --git a/tools/twine/LICENSE b/tools/twine/LICENSE
deleted file mode 100644
index 00585cc828..0000000000
--- a/tools/twine/LICENSE
+++ /dev/null
@@ -1,30 +0,0 @@
-Software License Agreement (BSD License)
-
-Copyright (c) 2012, Mobiata, LLC
-All rights reserved.
-
-Redistribution and use of this software in source and binary forms, with or
-without modification, are permitted provided that the following conditions are
-met:
-
-* Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-* Neither the name of the organization nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tools/twine/README.md b/tools/twine/README.md
deleted file mode 100644
index 6161d91037..0000000000
--- a/tools/twine/README.md
+++ /dev/null
@@ -1,232 +0,0 @@
-# Twine
-
-Twine is a command line tool for managing your strings and their translations. These are all stored in a master text file and then Twine uses this file to import and export localization files in a variety of types, including iOS and Mac OS X `.strings` files, Android `.xml` files, gettext `.po` files, and [jquery-localize][jquerylocalize] `.json` files. This allows individuals and companies to easily share translations across multiple projects, as well as export localization files in any format the user wants.
-
-## Install
-
-### As a Gem
-
-Twine is most easily installed as a Gem.
-
- $ gem install twine
-
-### From Source
-
-You can also run Twine directly from source. However, it requires [rubyzip][rubyzip] in order to create and read standard zip files.
-
- $ gem install rubyzip
- $ git clone git://github.com/mobiata/twine.git
- $ cd twine
- $ ./twine --help
-
-Make sure you run the `twine` executable at the root of the project as it properly sets up your Ruby library path. The `bin/twine` executable does not.
-
-## Twine File Format
-
-Twine stores everything in a single file, the Twine data file. The format of this file is a slight variant of the [Git][git] config file format, which itself is based on the old [Windows INI file][INI] format. The entire file is broken up into sections, which are created by placing the section name between two pairs of square brackets. Sections are optional, but they are the recommended way of grouping your definitions into smaller, more manageable chunks.
-
-Each grouping section contains N definitions. These definitions start with the key placed within a single pair of square brackets. It then contains a number of key-value pairs, including a comment, a comma-separated list of tags and all of the translations.
-
-### Placeholders
-
-Twine supports [`printf` style placeholders][printf] with one peculiarity: `@` is used for strings instead of `s`. This is because Twine started out as a tool for iOS and OS X projects.
-
-### Tags
-
-Tags are used by Twine as a way to only work with a subset of your definitions at any given point in time. Each definition can be assigned zero or more tags which are separated by commas. Tags are optional, though highly recommended. You can get a list of all definitions currently missing tags by executing the [`validate-twine-file`](#validate-twine-file) command with the `--pedantic` option.
-
-When generating a localization file, you can specify which definitions should be included using the `--tags` option. Provide a comma separated list of tags to match all definitions that contain any of the tags (`--tags tag1,tag2` matches all definitions tagged with `tag1` _or_ `tag2`). Provide multiple `--tags` options to match defintions containing all specified tags (`--tags tag1 --tags tag2` matches all definitions tagged with `tag1` _and_ `tag2`). You can match definitions _not_ containing a tag by prefixing the tag with a tilde (`--tags ~tag1` matches all definitions _not_ tagged with `tag1`). All three options are combinable.
-
-### Whitespace
-
-Whitepace in this file is mostly ignored. If you absolutely need to put spaces at the beginning or end of your translated string, you can wrap the entire string in a pair of `` ` `` characters. If your actual string needs to start *and* end with a grave accent, you can wrap it in another pair of `` ` `` characters. See the example, below.
-
-### References
-
-If you want a definition to inherit the values of another definition, you can use a reference. Any property not specified for a definition will be taken from the reference.
-
-### Example
-
-```ini
- [[General]]
- [yes]
- en = Yes
- es = Sí
- fr = Oui
- ja = はい
- [no]
- en = No
- fr = Non
- ja = いいえ
-
- [[Errors]]
- [path_not_found_error]
- en = The file '%@' could not be found.
- tags = app1,app6
- comment = An error describing when a path on the filesystem could not be found.
- [network_unavailable_error]
- en = The network is currently unavailable.
- tags = app1
- comment = An error describing when the device can not connect to the internet.
- [dismiss_error]
- ref = yes
- en = Dismiss
-
- [[Escaping Example]]
- [list_item_separator]
- en = `, `
- tags = mytag
- comment = A string that should be placed between multiple items in a list. For example: Red, Green, Blue
- [grave_accent_quoted_string]
- en = ``%@``
- tags = myothertag
- comment = This string will evaluate to `%@`.
-```
-
-## Supported Output Formats
-
-Twine currently supports the following output formats:
-
-* [iOS and OS X String Resources][applestrings] (format: apple)
-* [Android String Resources][androidstrings] (format: android)
-* [Gettext PO Files][gettextpo] (format: gettext)
-* [jquery-localize Language Files][jquerylocalize] (format: jquery)
-* [Django PO Files][djangopo] (format: django)
-* [Tizen String Resources][tizen] (format: tizen)
-* [Flash/Flex Properties][flash] (format: flash)
-
-If you would like to enable Twine to create localization files in another format, read the wiki page on how to create an appropriate formatter.
-
-## Usage
-
- Usage: twine COMMAND TWINE_FILE [INPUT_OR_OUTPUT_PATH] [--lang LANG1,LANG2...] [--tags TAG1,TAG2,TAG3...] [--format FORMAT]
-
-### Commands
-
-#### `generate-localization-file`
-
-This command creates a localization file from the Twine data file. If the output file would not contain any translations, Twine will exit with an error.
-
- $ twine generate-localization-file /path/to/twine.txt values-ja.xml --tags common,app1
- $ twine generate-localization-file /path/to/twine.txt Localizable.strings --lang ja --tags mytag
- $ twine generate-localization-file /path/to/twine.txt all-english.strings --lang en
-
-#### `generate-all-localization-files`
-
-This command is a convenient way to call [`generate-localization-file`](#generate-localization-file) multiple times. It uses standard conventions to figure out exactly which files to create given a parent directory. For example, if you point it to a parent directory containing `en.lproj`, `fr.lproj`, and `ja.lproj` subdirectories, Twine will create a `Localizable.strings` file of the appropriate language in each of them. However, files that would not contain any translations will not be created; instead warnings will be logged to `stderr`. This is often the command you will want to execute during the build phase of your project.
-
- $ twine generate-all-localization-files /path/to/twine.txt /path/to/project/locales/directory --tags common,app1
-
-#### `consume-localization-file`
-
-This command slurps all of the translations from a localization file and incorporates the translated strings into the Twine data file. This is a simple way to incorporate any changes made to a single file by one of your translators. It will only identify definitions that already exist in the data file.
-
- $ twine consume-localization-file /path/to/twine.txt fr.strings
- $ twine consume-localization-file /path/to/twine.txt Localizable.strings --lang ja
- $ twine consume-localization-file /path/to/twine.txt es.xml
-
-#### `consume-all-localization-files`
-
-This command reads in a folder containing many localization files. These files should be in a standard folder hierarchy so that Twine knows the language of each file. When combined with the `--developer-language`, `--consume-comments`, and `--consume-all` flags, this command is a great way to create your initial Twine data file from an existing project. Just make sure that you create a blank Twine data file first!
-
- $ twine consume-all-localization-files twine.txt Resources/Locales --developer-language en --consume-all --consume-comments
-
-#### `generate-localization-archive`
-
-This command is a convenient way to generate a zip file containing files created by the [`generate-localization-file`](#generate-localization-file) command. If a file would not contain any translated strings, it is skipped and a warning is logged to `stderr`. This command can be used to create a single zip containing a large number of translations in all languages which you can then hand off to your translation team.
-
- $ twine generate-localization-archive /path/to/twine.txt LocDrop1.zip
- $ twine generate-localization-archive /path/to/twine.txt LocDrop2.zip --lang en,fr,ja,ko --tags common,app1
-
-#### `consume-localization-archive`
-
-This command is a convenient way of taking a zip file and executing the [`consume-localization-file`](#consume-localization-file) command on each file within the archive. It is most often used to incorporate all of the changes made by the translation team after they have completed work on a localization archive.
-
- $ twine consume-localization-archive /path/to/twine.txt LocDrop2.zip
-
-#### `validate-twine-file`
-
-This command validates that the Twine data file can be parsed, contains no duplicate keys, and that no key contains invalid characters. It will exit with a non-zero status code if any of those criteria are not met.
-
- $ twine validate-twine-file /path/to/twine.txt
-
-## Creating Your First Twine Data File
-
-The easiest way to create your first Twine data file is to run the [`consume-all-localization-files`](#consume-all-localization-files) command. The one caveat is to first create a blank file to use as your starting point. Then, just point the `consume-all-localization-files` command at a directory in your project containing all of your localization files.
-
- $ touch twine.txt
- $ twine consume-all-localization-files twine.txt Resources/Locales --developer-language en --consume-all --consume-comments
-
-## Twine and Your Build Process
-
-### Xcode
-
-It is easy to incorporate Twine right into your iOS and OS X app build processes.
-
-1. In your project folder, create all of the `.lproj` directories that you need. It does not really matter where they are. We tend to put them in `Resources/Locales/`.
-2. Run the [`generate-all-localization-files`](#generate-all-localization-files) command to create all of the `.strings` files you need in these directories. For example,
-
- $ twine generate-all-localization-files twine.txt Resources/Locales/ --tags tag1,tag2
-
- Make sure you point Twine at your data file, the directory that contains all of your `.lproj` directories, and the tags that describe the definitions you want to use for this project.
-3. Drag the `Resources/Locales/` directory to the Xcode project navigator so that Xcode knows to include all of these `.strings` files in your build.
-4. In Xcode, navigate to the "Build Phases" tab of your target.
-5. Click on the "Add Build Phase" button and select "Add Run Script".
-6. Drag the new "Run Script" build phase up so that it runs earlier in the build process. It doesn't really matter where, as long as it happens before the resources are copied to your bundle.
-7. Edit your script to run the exact same command you ran in step (2) above.
-
-Now, whenever you build your application, Xcode will automatically invoke Twine to make sure that your `.strings` files are up-to-date.
-
-### Android Studio/Gradle
-
-Add the following task at the top level in app/build.gradle:
-```
-task generateLocalizations {
- String script = 'if hash twine 2>/dev/null; then twine generate-localization-file twine.txt ./src/main/res/values/generated_strings.xml; fi'
- exec {
- executable "sh"
- args '-c', script
- }
-}
-```
-
-Now every time you build your app the localization files are generated from the Twine file.
-
-
-## User Interface
-
-* [Twine TextMate 2 Bundle](https://github.com/mobiata/twine.tmbundle) — This [TextMate 2](https://github.com/textmate/textmate) bundle will make it easier for you to work with Twine files. In particular, it lets you use code folding to easily collapse and expand both definitions and sections.
-* [twine_ui](https://github.com/Daij-Djan/twine_ui) — A user interface for Twine written by [Dominik Pich](https://github.com/Daij-Djan/). Consider using this if you would prefer to use Twine without dropping to a command line.
-
-## Extending Twine
-
-If there's a format Twine does not yet support and you're keen to change that, check out the [documentation](documentation/formatters.md).
-
-## Contributors
-
-Many thanks to all of the contributors to the Twine project, including:
-
-* [Blake Watters](https://github.com/blakewatters)
-* [bootstraponline](https://github.com/bootstraponline)
-* [Ishitoya Kentaro](https://github.com/kent013)
-* [Joseph Earl](https://github.com/JosephEarl)
-* [Kevin Everets](https://github.com/keverets)
-* [Kevin Wood](https://github.com/kwood)
-* [Mohammad Hejazi](https://github.com/MohammadHejazi)
-* [Robert Guo](http://www.robertguo.me/)
-* [Sebastian Ludwig](https://github.com/sebastianludwig)
-* [Sergey Pisarchik](https://github.com/SergeyPisarchik)
-* [Shai Shamir](https://github.com/pichirichi)
-
-
-[rubyzip]: http://rubygems.org/gems/rubyzip
-[git]: http://git-scm.org/
-[INI]: http://en.wikipedia.org/wiki/INI_file
-[applestrings]: http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
-[androidstrings]: http://developer.android.com/guide/topics/resources/string-resource.html
-[gettextpo]: http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/PO-Files.html
-[jquerylocalize]: https://github.com/coderifous/jquery-localize
-[djangopo]: https://docs.djangoproject.com/en/dev/topics/i18n/translation/
-[tizen]: https://developer.tizen.org/documentation/articles/localization
-[flash]: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/resources/IResourceManager.html#getString()
-[printf]: https://en.wikipedia.org/wiki/Printf_format_string
diff --git a/tools/twine/Rakefile b/tools/twine/Rakefile
deleted file mode 100644
index de272d74f8..0000000000
--- a/tools/twine/Rakefile
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-
-Rake::TestTask.new do |t|
- t.libs = ['lib', 'test']
-end
-
-task :default => :test
diff --git a/tools/twine/bin/twine b/tools/twine/bin/twine
deleted file mode 100755
index da3cf272a8..0000000000
--- a/tools/twine/bin/twine
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-require 'twine'
-begin
- Twine::Runner.run(ARGV)
-rescue Twine::Error => e
- abort e.message
-end
diff --git a/tools/twine/lib/twine.rb b/tools/twine/lib/twine.rb
deleted file mode 100644
index ab02f7948e..0000000000
--- a/tools/twine/lib/twine.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-module Twine
- @@stdout = STDOUT
- @@stderr = STDERR
-
- def self.stdout
- @@stdout
- end
-
- def self.stdout=(out)
- @@stdout = out
- end
-
- def self.stderr
- @@stderr
- end
-
- def self.stderr=(err)
- @@stderr = err
- end
-
- class Error < StandardError
- end
-
- require 'twine/version'
- require 'twine/plugin'
- require 'twine/twine_file'
- require 'twine/encoding'
- require 'twine/output_processor'
- require 'twine/placeholders'
- require 'twine/formatters'
- require 'twine/formatters/abstract'
- require 'twine/formatters/android'
- require 'twine/formatters/apple'
- require 'twine/formatters/django'
- require 'twine/formatters/flash'
- require 'twine/formatters/gettext'
- require 'twine/formatters/jquery'
- require 'twine/formatters/tizen'
- require 'twine/runner'
- require 'twine/cli'
-end
diff --git a/tools/twine/lib/twine/cli.rb b/tools/twine/lib/twine/cli.rb
deleted file mode 100644
index f4c9b1a66c..0000000000
--- a/tools/twine/lib/twine/cli.rb
+++ /dev/null
@@ -1,409 +0,0 @@
-require 'optparse'
-require 'io/console'
-
-module Twine
- module CLI
- ALL_FORMATS = Formatters.formatters.map(&:format_name).map(&:downcase)
- OPTIONS = {
- consume_all: {
- switch: ['-a', '--[no-]consume-all'],
- description: 'Normally Twine will ignore any translation keys that do not exist in your Twine file.',
- boolean: true
- },
- consume_comments: {
- switch: ['-c', '--[no-]consume-comments'],
- description: <<-DESC,
- Normally Twine will ignore all comments in the file. With this flag set, any
- comments encountered will be read and parsed into the Twine data file. This is especially useful
- when creating your first Twine data file from an existing project.
- DESC
- boolean: true
- },
- create_folders: {
- switch: ['-r', '--[no-]create-folders'],
- description: <<-DESC,
- This flag may be used to create output folders for all languages, if they don't exist yet.
- As a result all languages will be exported, not only the ones where an output folder already exists.
- DESC
- boolean: true
- },
- developer_language: {
- switch: ['-d', '--developer-language LANG'],
- description: <<-DESC,
- When writing the Twine data file, set the specified language as the "developer language". In
- practice, this just means that this language will appear first in the Twine data file. When
- generating files this language will be used as default language and its translations will be
- used if a definition is not localized for the output language.
- DESC
- },
- encoding: {
- switch: ['-e', '--encoding ENCODING'],
- description: <<-DESC,
- Twine defaults to encoding all output files in UTF-8. This flag will tell Twine to use an alternate
- encoding for these files. For example, you could use this to write Apple .strings files in UTF-16.
- When reading files, Twine does its best to determine the encoding automatically. However, if the
- files are UTF-16 without BOM, you need to specify if it's UTF-16LE or UTF16-BE.
- DESC
- },
- file_name: {
- switch: ['-n', '--file-name FILE_NAME'],
- description: 'This flag may be used to overwrite the default file name of the format.'
- },
- format: {
- switch: ['-f', '--format FORMAT', ALL_FORMATS],
- description: <<-DESC,
- The file format to read or write: (#{ALL_FORMATS.join(', ')}). Additional formatters can be placed in the formats/ directory.
- DESC
- },
- :include => {
- switch: ['-i', '--include SET', [:all, :translated, :untranslated]],
- description: <<-DESC,
- This flag will determine which definitions are included. It's possible values are:
- all: All definitions both translated and untranslated for the specified language are included.
- This is the default value.
- translated: Only definitions with translation for the specified language are included.
- untranslated: Only definitions without translation for the specified language are included.
- DESC
- default: :all
- },
- languages: {
- switch: ['-l', '--lang LANGUAGES', Array],
- description: 'Comma separated list of language codes to use for the specified action.'
- },
- output_path: {
- switch: ['-o', '--output-file OUTPUT_FILE'],
- description: 'Write a new Twine file at this location instead of replacing the original file.'
- },
- pedantic: {
- switch: ['-p', '--[no-]pedantic'],
- description: 'When validating a Twine file, perform additional checks that go beyond pure validity (like presence of tags).'
- },
- tags: {
- switch: ['-t', '--tags TAG1,TAG2,TAG3', Array],
- description: <<-DESC,
- Only definitions with ANY of the specified tags will be processed. Specify this option multiple
- times to only include definitions with ALL of the specified tags. Prefix a tag with ~ to include
- definitions NOT containing that tag. Omit this option to match all definitions in the Twine data file.
- DESC
- repeated: true
- },
- untagged: {
- switch: ['-u', '--[no-]untagged'],
- description: <<-DESC,
- If you have specified tags using the --tags flag, then only those tags will be selected. If you also
- want to select all definitions that are untagged, then you can specify this option to do so.
- DESC
- },
- validate: {
- switch: ['--[no-]validate'],
- description: 'Validate the Twine file before formatting it.'
- }
- }
-
- COMMANDS = {
- 'generate-localization-file' => {
- description: 'Generates a localization file in a certain LANGUAGE given a particular FORMAT. This script will attempt to guess both the language and the format given the filename and extension. For example, "ko.xml" will generate a Korean language file for Android.',
- arguments: [:twine_file, :output_path],
- optional_options: [
- :developer_language,
- :encoding,
- :format,
- :include,
- :languages,
- :tags,
- :untagged,
- :validate
- ],
- option_validation: Proc.new { |options|
- if options[:languages] and options[:languages].length > 1
- raise Twine::Error.new 'specify only a single language for the `generate-localization-file` command.'
- end
- },
- example: 'twine generate-localization-file twine.txt ko.xml --tags FT'
- },
- 'generate-all-localization-files' => {
- description: 'Generates all the localization files necessary for a given project. The parent directory to all of the locale-specific directories in your project should be specified as the INPUT_OR_OUTPUT_PATH. This command will most often be executed by your build script so that each build always contains the most recent translations.',
- arguments: [:twine_file, :output_path],
- optional_options: [
- :create_folders,
- :developer_language,
- :encoding,
- :file_name,
- :format,
- :include,
- :tags,
- :untagged,
- :validate
- ],
- example: 'twine generate-all-localization-files twine.txt Resources/Locales/ --tags FT,FB'
- },
- 'generate-localization-archive' => {
- description: 'Generates a zip archive of localization files in a given format. The purpose of this command is to create a very simple archive that can be handed off to a translation team. The translation team can unzip the archive, translate all of the strings in the archived files, zip everything back up, and then hand that final archive back to be consumed by the consume-localization-archive command.',
- arguments: [:twine_file, :output_path],
- required_options: [
- :format
- ],
- optional_options: [
- :developer_language,
- :encoding,
- :include,
- :tags,
- :untagged,
- :validate
- ],
- example: 'twine generate-localization-archive twine.txt LocDrop5.zip --tags FT,FB --format android --lang de,en,en-GB,ja,ko'
- },
- 'consume-localization-file' => {
- description: 'Slurps all of the translations from a localization file into the specified TWINE_FILE. If you have some files returned to you by your translators you can use this command to incorporate all of their changes. This script will attempt to guess both the language and the format given the filename and extension. For example, "ja.strings" will assume that the file is a Japanese iOS strings file.',
- arguments: [:twine_file, :input_path],
- optional_options: [
- :consume_all,
- :consume_comments,
- :developer_language,
- :encoding,
- :format,
- :languages,
- :output_path,
- :tags
- ],
- option_validation: Proc.new { |options|
- if options[:languages] and options[:languages].length > 1
- raise Twine::Error.new 'specify only a single language for the `consume-localization-file` command.'
- end
- },
- example: 'twine consume-localization-file twine.txt ja.strings'
- },
- 'consume-all-localization-files' => {
- description: 'Slurps all of the translations from a directory into the specified TWINE_FILE. If you have some files returned to you by your translators you can use this command to incorporate all of their changes. This script will attempt to guess both the language and the format given the filename and extension. For example, "ja.strings" will assume that the file is a Japanese iOS strings file.',
- arguments: [:twine_file, :input_path],
- optional_options: [
- :consume_all,
- :consume_comments,
- :developer_language,
- :encoding,
- :format,
- :output_path,
- :tags
- ],
- example: 'twine consume-all-localization-files twine.txt Resources/Locales/ --developer-language en --tags DefaultTag1,DefaultTag2'
- },
- 'consume-localization-archive' => {
- description: 'Consumes an archive of translated files. This archive should be in the same format as the one created by the generate-localization-archive command.',
- arguments: [:twine_file, :input_path],
- optional_options: [
- :consume_all,
- :consume_comments,
- :developer_language,
- :encoding,
- :format,
- :output_path,
- :tags
- ],
- example: 'twine consume-localization-archive twine.txt LocDrop5.zip'
- },
- 'validate-twine-file' => {
- description: 'Validates that the given Twine file is parseable, contains no duplicates, and that no key contains invalid characters. Exits with a non-zero exit code if those criteria are not met.',
- arguments: [:twine_file],
- optional_options: [
- :developer_language,
- :pedantic
- ],
- example: 'twine validate-twine-file twine.txt'
- }
- }
- DEPRECATED_COMMAND_MAPPINGS = {
- 'generate-loc-drop' => 'generate-localization-archive', # added on 17.01.2017 - version 0.10
- 'consume-loc-drop' => 'consume-localization-archive' # added on 17.01.2017 - version 0.10
- }
-
- def self.parse(args)
- command = args.select { |a| a[0] != '-' }[0]
- args = args.reject { |a| a == command }
-
- mapped_command = DEPRECATED_COMMAND_MAPPINGS[command]
- if mapped_command
- Twine::stderr.puts "WARNING: Twine commands names have changed. `#{command}` is now `#{mapped_command}`. The old command is deprecated will soon stop working. For more information please check the documentation at https://github.com/mobiata/twine"
- command = mapped_command
- end
-
- unless COMMANDS.keys.include? command
- Twine::stderr.puts "Invalid command: #{command}" unless command.nil?
- print_help(args)
- abort
- end
-
- options = parse_command_options(command, args)
-
- return options
- end
-
- private
-
- def self.print_help(args)
- verbose = false
-
- help_parser = OptionParser.new
- help_parser.banner = 'Usage: twine [command] [options]'
-
- help_parser.define('-h', '--help', 'Show this message.')
- help_parser.define('--verbose', 'More detailed help.') { verbose = true }
-
- help_parser.parse!(args)
-
- Twine::stdout.puts help_parser.help
- Twine::stdout.puts ''
-
-
- Twine::stdout.puts 'Commands:'
-
- COMMANDS.each do |name, properties|
- if verbose
- Twine::stdout.puts ''
- Twine::stdout.puts ''
- Twine::stdout.puts "# #{name}"
- Twine::stdout.puts ''
- Twine::stdout.puts properties[:description]
- else
- Twine::stdout.puts "- #{name}"
- end
- end
-
- Twine::stdout.puts ''
- Twine::stdout.puts 'type `twine [command] --help` for further information about a command.'
- end
-
- # source: https://www.safaribooksonline.com/library/view/ruby-cookbook/0596523696/ch01s15.html
- def self.word_wrap(s, width)
- s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n").rstrip
- end
-
- def self.indent(string, first_line, following_lines)
- lines = string.split("\n")
- indentation = ' ' * following_lines
- lines.map! { |line| indentation + line }
- result = lines.join("\n").strip
- ' ' * first_line + result
- end
-
- # ensure the description forms a neat block on the right
- def self.prepare_description!(options, summary_width)
- lines = options[:description].split "\n"
-
- # remove leadinge HEREDOC spaces
- space_match = lines[0].match(/^\s+/)
- if space_match
- leading_spaces = space_match[0].length
- lines.map! { |l| l[leading_spaces..-1] }
- end
-
- merged_lines = []
- lines.each do |line|
- # if the line is a continuation of the previous one
- if not merged_lines.empty? and (line[0] != ' ' or line[0, 4] == ' ')
- merged_lines[-1] += ' ' + line.strip
- else
- merged_lines << line.rstrip
- end
- end
-
- if IO.console
- console_width = IO.console.winsize[1]
- else
- console_width = 100
- end
- summary_width += 7 # account for description padding
- max_description_width = console_width - summary_width
- merged_lines.map! do |line|
- if line[0] == ' '
- line = word_wrap(line.strip, max_description_width - 2)
- line = indent(line, 2, 4)
- else
- line = word_wrap(line, max_description_width)
- end
- line
- end
-
- options[:switch] << indent(merged_lines.join("\n"), 0, summary_width)
- end
-
- def self.parse_command_options(command_name, args)
- command = COMMANDS[command_name]
-
- result = {
- command: command_name
- }
-
- parser = OptionParser.new
- parser.banner = "Usage: twine #{command_name} #{command[:arguments].map { |c| "[#{c}]" }.join(' ')} [options]"
-
- [:required_options, :optional_options].each do |option_type|
- options = command[option_type]
- if options and options.size > 0
- parser.separator ''
- parser.separator option_type.to_s.gsub('_', ' ').capitalize + ":"
-
- options.each do |option_name|
- option = OPTIONS[option_name]
-
- result[option_name] = option[:default] if option[:default]
-
- prepare_description!(option, parser.summary_width)
-
- parser.define(*option[:switch]) do |value|
- if option[:repeated]
- result[option_name] = (result[option_name] || []) << value
- elsif option[:boolean]
- result[option_name] = true
- else
- result[option_name] = value
- end
- end
- end
- end
- end
-
- parser.define('-h', '--help', 'Show this message.') do
- puts parser.help
- exit
- end
-
- parser.separator ''
- parser.separator 'Examples:'
- parser.separator ''
- parser.separator "> #{command[:example]}"
-
- begin
- parser.parse! args
- rescue OptionParser::ParseError => e
- raise Twine::Error.new e.message
- end
-
- arguments = args.reject { |a| a[0] == '-' }
- number_of_missing_arguments = command[:arguments].size - arguments.size
- if number_of_missing_arguments > 0
- missing_arguments = command[:arguments][-number_of_missing_arguments, number_of_missing_arguments]
- raise Twine::Error.new "#{number_of_missing_arguments} missing argument#{number_of_missing_arguments > 1 ? "s" : ""}: #{missing_arguments.join(', ')}. Check `twine #{command_name} -h`"
- end
-
- if args.length > command[:arguments].size
- raise Twine::Error.new "Unknown argument: #{args[command[:arguments].size]}"
- end
-
- if command[:required_options]
- command[:required_options].each do |option_name|
- if result[option_name] == nil
- raise Twine::Error.new "missing option: #{OPTIONS[option_name][:switch][0]}"
- end
- end
- end
-
- command[:option_validation].call(result) if command[:option_validation]
-
- command[:arguments].each do |argument_name|
- result[argument_name] = args.shift
- end
-
- result
- end
- end
-end
diff --git a/tools/twine/lib/twine/encoding.rb b/tools/twine/lib/twine/encoding.rb
deleted file mode 100644
index 7cdd7102b5..0000000000
--- a/tools/twine/lib/twine/encoding.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-module Twine
- module Encoding
-
- def self.bom(path)
- first_bytes = IO.binread(path, 2)
- return nil unless first_bytes
- first_bytes = first_bytes.codepoints.map.to_a
- return 'UTF-16BE' if first_bytes == [0xFE, 0xFF]
- return 'UTF-16LE' if first_bytes == [0xFF, 0xFE]
- rescue EOFError
- return nil
- end
-
- def self.has_bom?(path)
- !bom(path).nil?
- end
-
- def self.encoding_for_path(path)
- bom(path) || 'UTF-8'
- end
- end
-end
diff --git a/tools/twine/lib/twine/formatters.rb b/tools/twine/lib/twine/formatters.rb
deleted file mode 100644
index 49f4aa551a..0000000000
--- a/tools/twine/lib/twine/formatters.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-module Twine
- module Formatters
- @formatters = []
-
- class << self
- attr_reader :formatters
-
- ###
- # registers a new formatter
- #
- # formatter_class - the class of the formatter to register
- #
- # returns array of active formatters
- #
- def register_formatter formatter_class
- @formatters << formatter_class.new
- end
- end
- end
-end
diff --git a/tools/twine/lib/twine/formatters/abstract.rb b/tools/twine/lib/twine/formatters/abstract.rb
deleted file mode 100644
index 4bd8c09377..0000000000
--- a/tools/twine/lib/twine/formatters/abstract.rb
+++ /dev/null
@@ -1,163 +0,0 @@
-require 'fileutils'
-
-module Twine
- module Formatters
- class Abstract
- attr_accessor :twine_file
- attr_accessor :options
-
- def initialize
- @twine_file = TwineFile.new
- @options = {}
- end
-
- def format_name
- raise NotImplementedError.new("You must implement format_name in your formatter class.")
- end
-
- def extension
- raise NotImplementedError.new("You must implement extension in your formatter class.")
- end
-
- def can_handle_directory?(path)
- Dir.entries(path).any? { |item| /^.+#{Regexp.escape(extension)}$/.match(item) }
- end
-
- def default_file_name
- raise NotImplementedError.new("You must implement default_file_name in your formatter class.")
- end
-
- def set_translation_for_key(key, lang, value)
- value = value.gsub("\n", "\\n")
-
- if @twine_file.definitions_by_key.include?(key)
- definition = @twine_file.definitions_by_key[key]
- reference = @twine_file.definitions_by_key[definition.reference_key] if definition.reference_key
-
- if !reference or value != reference.translations[lang]
- definition.translations[lang] = value
- end
- elsif @options[:consume_all]
- Twine::stderr.puts "Adding new definition '#{key}' to twine file."
- current_section = @twine_file.sections.find { |s| s.name == 'Uncategorized' }
- unless current_section
- current_section = TwineSection.new('Uncategorized')
- @twine_file.sections.insert(0, current_section)
- end
- current_definition = TwineDefinition.new(key)
- current_section.definitions << current_definition
-
- if @options[:tags] && @options[:tags].length > 0
- current_definition.tags = @options[:tags]
- end
-
- @twine_file.definitions_by_key[key] = current_definition
- @twine_file.definitions_by_key[key].translations[lang] = value
- else
- Twine::stderr.puts "Warning: '#{key}' not found in twine file."
- end
- if !@twine_file.language_codes.include?(lang)
- @twine_file.add_language_code(lang)
- end
- end
-
- def set_comment_for_key(key, comment)
- return unless @options[:consume_comments]
-
- if @twine_file.definitions_by_key.include?(key)
- definition = @twine_file.definitions_by_key[key]
-
- reference = @twine_file.definitions_by_key[definition.reference_key] if definition.reference_key
-
- if !reference or comment != reference.raw_comment
- definition.comment = comment
- end
- end
- end
-
- def determine_language_given_path(path)
- raise NotImplementedError.new("You must implement determine_language_given_path in your formatter class.")
- end
-
- def output_path_for_language(lang)
- lang
- end
-
- def read(io, lang)
- raise NotImplementedError.new("You must implement read in your formatter class.")
- end
-
- def format_file(lang)
- output_processor = Processors::OutputProcessor.new(@twine_file, @options)
- processed_twine_file = output_processor.process(lang)
-
- return nil if processed_twine_file.definitions_by_key.empty?
-
- header = format_header(lang)
- result = ""
- result += header + "\n" if header
- result += format_sections(processed_twine_file, lang)
- end
-
- def format_header(lang)
- end
-
- def format_sections(twine_file, lang)
- sections = twine_file.sections.map { |section| format_section(section, lang) }
- sections.compact.join("\n")
- end
-
- def format_section_header(section)
- end
-
- def should_include_definition(definition, lang)
- return !definition.translation_for_lang(lang).nil?
- end
-
- def format_section(section, lang)
- definitions = section.definitions.select { |definition| should_include_definition(definition, lang) }
- return if definitions.empty?
-
- result = ""
-
- if section.name && section.name.length > 0
- section_header = format_section_header(section)
- result += "\n#{section_header}" if section_header
- end
-
- definitions.map! { |definition| format_definition(definition, lang) }
- definitions.compact! # remove nil definitions
- definitions.map! { |definition| "\n#{definition}" } # prepend newline
- result += definitions.join
- end
-
- def format_definition(definition, lang)
- [format_comment(definition, lang), format_key_value(definition, lang)].compact.join
- end
-
- def format_comment(definition, lang)
- end
-
- def format_key_value(definition, lang)
- value = definition.translation_for_lang(lang)
- key_value_pattern % { key: format_key(definition.key.dup), value: format_value(value.dup) }
- end
-
- def key_value_pattern
- raise NotImplementedError.new("You must implement key_value_pattern in your formatter class.")
- end
-
- def format_key(key)
- key
- end
-
- def format_value(value)
- value
- end
-
- def escape_quotes(text)
- text.gsub('"', '\\\\"')
- end
- end
- end
-end
diff --git a/tools/twine/lib/twine/formatters/android.rb b/tools/twine/lib/twine/formatters/android.rb
deleted file mode 100644
index 9a65fca9fd..0000000000
--- a/tools/twine/lib/twine/formatters/android.rb
+++ /dev/null
@@ -1,158 +0,0 @@
-# encoding: utf-8
-require 'cgi'
-require 'rexml/document'
-
-module Twine
- module Formatters
- class Android < Abstract
- include Twine::Placeholders
-
- LANG_CODES = Hash[
- 'zh' => 'zh-Hans',
- 'zh-CN' => 'zh-Hans',
- 'zh-HK' => 'zh-Hant',
- 'en-GB' => 'en-GB',
- 'in' => 'id'
- ]
-
- def format_name
- 'android'
- end
-
- def extension
- '.xml'
- end
-
- def can_handle_directory?(path)
- Dir.entries(path).any? { |item| /^values.*$/.match(item) }
- end
-
- def default_file_name
- 'strings.xml'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- if segment == 'values'
- return @twine_file.language_codes[0]
- else
- # The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").
- # see http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
- match = /^values-([a-z]{2}(-r[a-z]{2})?)$/i.match(segment)
-
- if match
- lang = match[1].sub('-r', '-')
- return LANG_CODES.fetch(lang, lang)
- end
- end
- end
-
- return
- end
-
- def output_path_for_language(lang)
- "values-#{lang}"
- end
-
- def set_translation_for_key(key, lang, value)
- value = CGI.unescapeHTML(value)
- value.gsub!('\\\'', '\'')
- value.gsub!('\\"', '"')
- value = convert_placeholders_from_android_to_twine(value)
- value.gsub!('\@', '@')
- value.gsub!(/(\\u0020)*|(\\u0020)*\z/) { |spaces| ' ' * (spaces.length / 6) }
- super(key, lang, value)
- end
-
- def read(io, lang)
- document = REXML::Document.new io, :compress_whitespace => %w{ string }
-
- comment = nil
- document.root.children.each do |child|
- if child.is_a? REXML::Comment
- content = child.string.strip
- comment = content if content.length > 0 and not content.start_with?("SECTION:")
- elsif child.is_a? REXML::Element
- next unless child.name == 'string'
-
- key = child.attributes['name']
-
- set_translation_for_key(key, lang, child.text)
- set_comment_for_key(key, comment) if comment
-
- comment = nil
- end
- end
- end
-
- def format_header(lang)
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Android Strings File -->\n<!-- Generated by Twine #{Twine::VERSION} -->\n<!-- Language: #{lang} -->"
- end
-
- def format_sections(twine_file, lang)
- result = '<resources>'
-
- result += super + "\n"
-
- result += "</resources>\n"
- end
-
- def format_section_header(section)
- "\t<!-- SECTION: #{section.name} -->"
- end
-
- def format_comment(definition, lang)
- "\t<!-- #{definition.comment.gsub('--', '—')} -->\n" if definition.comment
- end
-
- def key_value_pattern
- "\t<string name=\"%{key}\">%{value}</string>"
- end
-
- def escape_value(value)
- # escape double and single quotes, & signs and tags
- value = escape_quotes(value)
- value.gsub!("'", "\\\\'")
- value.gsub!(/&/, '&amp;')
- value.gsub!('<', '&lt;')
-
- # escape non resource identifier @ signs (http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromXml)
- resource_identifier_regex = /@(?!([a-z\.]+:)?[a-z+]+\/[a-zA-Z_]+)/ # @[<package_name>:]<resource_type>/<resource_name>
- value.gsub(resource_identifier_regex, '\@')
- end
-
- # see http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
- # however unescaped HTML markup like in "Welcome to <b>Android</b>!" is stripped when retrieved with getString() (http://stackoverflow.com/questions/9891996/)
- def format_value(value)
- value = value.dup
-
- # convert placeholders (e.g. %@ -> %s)
- value = convert_placeholders_from_twine_to_android(value)
-
- # capture xliff tags and replace them with a placeholder
- xliff_tags = []
- value.gsub! /<xliff:g.+?<\/xliff:g>/ do
- xliff_tags << $&
- 'TWINE_XLIFF_TAG_PLACEHOLDER'
- end
-
- # escape everything outside xliff tags
- value = escape_value(value)
-
- # put xliff tags back into place
- xliff_tags.each do |xliff_tag|
- # escape content of xliff tags
- xliff_tag.gsub! /(<xliff:g.*?>)(.*)(<\/xliff:g>)/ do "#{$1}#{escape_value($2)}#{$3}" end
- value.sub! 'TWINE_XLIFF_TAG_PLACEHOLDER', xliff_tag
- end
-
- # replace beginning and end spaces with \u0020. Otherwise Android strips them.
- value.gsub(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
- end
-
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Android.new
diff --git a/tools/twine/lib/twine/formatters/apple.rb b/tools/twine/lib/twine/formatters/apple.rb
deleted file mode 100644
index 44ce7a41dd..0000000000
--- a/tools/twine/lib/twine/formatters/apple.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-module Twine
- module Formatters
- class Apple < Abstract
- def format_name
- 'apple'
- end
-
- def extension
- '.strings'
- end
-
- def can_handle_directory?(path)
- Dir.entries(path).any? { |item| /^.+\.lproj$/.match(item) }
- end
-
- def default_file_name
- 'Localizable.strings'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- match = /^(.+)\.lproj$/.match(segment)
- if match
- if match[1] != "Base"
- return match[1]
- end
- end
- end
-
- return
- end
-
- def output_path_for_language(lang)
- "#{lang}.lproj"
- end
-
- def read(io, lang)
- last_comment = nil
- while line = io.gets
- # matches a `key = "value"` line, where key may be quoted or unquoted. The former may also contain escaped characters
- match = /^\s*((?:"(?:[^"\\]|\\.)+")|(?:[^"\s=]+))\s*=\s*"((?:[^"\\]|\\.)*)"/.match(line)
- if match
- key = match[1]
- key = key[1..-2] if key[0] == '"' and key[-1] == '"'
- key.gsub!('\\"', '"')
- value = match[2]
- value.gsub!('\\"', '"')
- set_translation_for_key(key, lang, value)
- if last_comment
- set_comment_for_key(key, last_comment)
- end
- end
-
- match = /\/\* (.*) \*\//.match(line)
- if match
- last_comment = match[1]
- else
- last_comment = nil
- end
- end
- end
-
- def format_header(lang)
- "/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n * Language: #{lang}\n */"
- end
-
- def format_section_header(section)
- "/********** #{section.name} **********/\n"
- end
-
- def key_value_pattern
- "\"%{key}\" = \"%{value}\";\n"
- end
-
- def format_comment(definition, lang)
- "/* #{definition.comment.gsub('*/', '* /')} */\n" if definition.comment
- end
-
- def format_key(key)
- escape_quotes(key)
- end
-
- def format_value(value)
- escape_quotes(value)
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Apple.new
diff --git a/tools/twine/lib/twine/formatters/django.rb b/tools/twine/lib/twine/formatters/django.rb
deleted file mode 100644
index 5c8876665a..0000000000
--- a/tools/twine/lib/twine/formatters/django.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-module Twine
- module Formatters
- class Django < Abstract
- def format_name
- 'django'
- end
-
- def extension
- '.po'
- end
-
- def default_file_name
- 'strings.po'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- match = /(..)\.po$/.match(segment)
- return match[1] if match
- end
-
- return
- end
-
- def read(io, lang)
- comment_regex = /#\. *"?(.*)"?$/
- key_regex = /msgid *"(.*)"$/
- value_regex = /msgstr *"(.*)"$/m
-
- last_comment = nil
- while line = io.gets
- comment_match = comment_regex.match(line)
- if comment_match
- comment = comment_match[1]
- end
-
- key_match = key_regex.match(line)
- if key_match
- key = key_match[1].gsub('\\"', '"')
- end
- value_match = value_regex.match(line)
- if value_match
- value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
- end
-
- if key and key.length > 0 and value and value.length > 0
- set_translation_for_key(key, lang, value)
- if comment and comment.length > 0 and !comment.start_with?("--------- ")
- set_comment_for_key(key, comment)
- end
- key = nil
- value = nil
- comment = nil
- end
- end
- end
-
- def format_file(lang)
- @default_lang = @twine_file.language_codes[0]
- result = super
- @default_lang = nil
- result
- end
-
- def format_header(lang)
- "##\n # Django Strings File\n # Generated by Twine #{Twine::VERSION}\n # Language: #{lang}\nmsgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\""
- end
-
- def format_section_header(section)
- "#--------- #{section.name} ---------#\n"
- end
-
- def format_definition(definition, lang)
- [format_comment(definition, lang), format_base_translation(definition), format_key_value(definition, lang)].compact.join
- end
-
- def format_base_translation(definition)
- base_translation = definition.translations[@default_lang]
- "# base translation: \"#{base_translation}\"\n" if base_translation
- end
-
- def key_value_pattern
- "msgid \"%{key}\"\n" +
- "msgstr \"%{value}\"\n"
- end
-
- def format_comment(definition, lang)
- "#. #{escape_quotes(definition.comment)}\n" if definition.comment
- end
-
- def format_key(key)
- escape_quotes(key)
- end
-
- def format_value(value)
- escape_quotes(value)
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Django.new
diff --git a/tools/twine/lib/twine/formatters/flash.rb b/tools/twine/lib/twine/formatters/flash.rb
deleted file mode 100644
index 54fc3366f8..0000000000
--- a/tools/twine/lib/twine/formatters/flash.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-module Twine
- module Formatters
- class Flash < Abstract
- include Twine::Placeholders
-
- def format_name
- 'flash'
- end
-
- def extension
- '.properties'
- end
-
- def default_file_name
- 'resources.properties'
- end
-
- def determine_language_given_path(path)
- # match two-letter language code, optionally followed by a two letter region code
- path.split(File::SEPARATOR).reverse.find { |segment| segment =~ /^([a-z]{2}(-[a-z]{2})?)$/i }
- end
-
- def set_translation_for_key(key, lang, value)
- value = convert_placeholders_from_flash_to_twine(value)
- super(key, lang, value)
- end
-
- def read(io, lang)
- last_comment = nil
- while line = io.gets
- match = /((?:[^"\\]|\\.)+)\s*=\s*((?:[^"\\]|\\.)*)/.match(line)
- if match
- key = match[1]
- value = match[2].strip
-
- set_translation_for_key(key, lang, value)
- set_comment_for_key(key, last_comment) if last_comment
- end
-
- match = /# *(.*)/.match(line)
- last_comment = match ? match[1] : nil
- end
- end
-
- def format_sections(twine_file, lang)
- super + "\n"
- end
-
- def format_header(lang)
- "## Flash Strings File\n## Generated by Twine #{Twine::VERSION}\n## Language: #{lang}"
- end
-
- def format_section_header(section)
- "## #{section.name} ##\n"
- end
-
- def format_comment(definition, lang)
- "# #{definition.comment}\n" if definition.comment
- end
-
- def key_value_pattern
- "%{key}=%{value}"
- end
-
- def format_value(value)
- convert_placeholders_from_twine_to_flash(value)
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Flash.new
diff --git a/tools/twine/lib/twine/formatters/gettext.rb b/tools/twine/lib/twine/formatters/gettext.rb
deleted file mode 100644
index d63e944ca3..0000000000
--- a/tools/twine/lib/twine/formatters/gettext.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-# encoding: utf-8
-
-module Twine
- module Formatters
- class Gettext < Abstract
- def format_name
- 'gettext'
- end
-
- def extension
- '.po'
- end
-
- def default_file_name
- 'strings.po'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- match = /(..)\.po$/.match(segment)
- if match
- return match[1]
- end
- end
-
- return
- end
-
- def read(io, lang)
- comment_regex = /#.? *"(.*)"$/
- key_regex = /msgctxt *"(.*)"$/
- value_regex = /msgstr *"(.*)"$/m
-
- while item = io.gets("\n\n")
- key = nil
- value = nil
- comment = nil
-
- comment_match = comment_regex.match(item)
- if comment_match
- comment = comment_match[1]
- end
- key_match = key_regex.match(item)
- if key_match
- key = key_match[1].gsub('\\"', '"')
- end
- value_match = value_regex.match(item)
- if value_match
- value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
- end
- if key and key.length > 0 and value and value.length > 0
- set_translation_for_key(key, lang, value)
- if comment and comment.length > 0 and !comment.start_with?("SECTION:")
- set_comment_for_key(key, comment)
- end
- comment = nil
- end
- end
- end
-
- def format_file(lang)
- @default_lang = twine_file.language_codes[0]
- result = super
- @default_lang = nil
- result
- end
-
- def format_header(lang)
- "msgid \"\"\nmsgstr \"\"\n\"Language: #{lang}\\n\"\n\"X-Generator: Twine #{Twine::VERSION}\\n\"\n"
- end
-
- def format_section_header(section)
- "# SECTION: #{section.name}"
- end
-
- def should_include_definition(definition, lang)
- super and !definition.translation_for_lang(@default_lang).nil?
- end
-
- def format_comment(definition, lang)
- "#. \"#{escape_quotes(definition.comment)}\"\n" if definition.comment
- end
-
- def format_key_value(definition, lang)
- value = definition.translation_for_lang(lang)
- [format_key(definition.key.dup), format_base_translation(definition), format_value(value.dup)].compact.join
- end
-
- def format_key(key)
- "msgctxt \"#{key}\"\n"
- end
-
- def format_base_translation(definition)
- "msgid \"#{definition.translations[@default_lang]}\"\n"
- end
-
- def format_value(value)
- "msgstr \"#{value}\"\n"
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Gettext.new
diff --git a/tools/twine/lib/twine/formatters/jquery.rb b/tools/twine/lib/twine/formatters/jquery.rb
deleted file mode 100644
index e6eb495582..0000000000
--- a/tools/twine/lib/twine/formatters/jquery.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-module Twine
- module Formatters
- class JQuery < Abstract
- def format_name
- 'jquery'
- end
-
- def extension
- '.json'
- end
-
- def default_file_name
- 'localize.json'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- match = /^(.+)\.json$/.match(segment)
- if match
- return match[1]
- end
- end
-
- return
- end
-
- def read(io, lang)
- begin
- require "json"
- rescue LoadError
- raise Twine::Error.new "You must run 'gem install json' in order to read or write jquery-localize files."
- end
-
- json = JSON.load(io)
- json.each do |key, value|
- set_translation_for_key(key, lang, value)
- end
- end
-
- def format_file(lang)
- result = super
- return result unless result
- "{\n#{super}\n}\n"
- end
-
- def format_sections(twine_file, lang)
- sections = twine_file.sections.map { |section| format_section(section, lang) }
- sections.delete_if &:empty?
- sections.join(",\n\n")
- end
-
- def format_section_header(section)
- end
-
- def format_section(section, lang)
- definitions = section.definitions.dup
-
- definitions.map! { |definition| format_definition(definition, lang) }
- definitions.compact! # remove nil definitions
- definitions.join(",\n")
- end
-
- def key_value_pattern
- "\"%{key}\":\"%{value}\""
- end
-
- def format_key(key)
- escape_quotes(key)
- end
-
- def format_value(value)
- escape_quotes(value)
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::JQuery.new
diff --git a/tools/twine/lib/twine/formatters/tizen.rb b/tools/twine/lib/twine/formatters/tizen.rb
deleted file mode 100644
index 5df03c35f4..0000000000
--- a/tools/twine/lib/twine/formatters/tizen.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-# encoding: utf-8
-require 'cgi'
-require 'rexml/document'
-
-module Twine
- module Formatters
- class Tizen < Abstract
- include Twine::Placeholders
-
- LANG_CODES = Hash[
- 'eng-GB' => 'en',
- 'rus-RU' => 'ru',
- 'fra-FR' => 'fr',
- 'deu-DE' => 'de',
- 'spa-ES' => 'es',
- 'ita-IT' => 'it',
- 'ces-CZ' => 'cs',
- 'pol-PL' => 'pl',
- 'por-PT' => 'pt',
- 'ukr-UA' => 'uk'
- ]
-
- def format_name
- 'tizen'
- end
-
- def extension
- '.xml'
- end
-
- def can_handle_directory?(path)
- Dir.entries(path).any? { |item| /^values.*$/.match(item) }
- end
-
- def default_file_name
- 'strings.xml'
- end
-
- def determine_language_given_path(path)
- path_arr = path.split(File::SEPARATOR)
- path_arr.each do |segment|
- match = /^(.*-.*)\.xml$/.match(segment)
- if match
- lang = match[1]
- lang = LANG_CODES.fetch(lang, nil)
- return lang
- end
- end
- return
- end
-
- def read(io, lang)
- resources_regex = /<resources(?:[^>]*)>(.*)<\/resources>/m
- key_regex = /<string name="(\w+)">/
- comment_regex = /<!-- (.*) -->/
- value_regex = /<string name="\w+">(.*)<\/string>/
- key = nil
- value = nil
- comment = nil
-
- content_match = resources_regex.match(io.read)
- if content_match
- for line in content_match[1].split(/\r?\n/)
- key_match = key_regex.match(line)
- if key_match
- key = key_match[1]
- value_match = value_regex.match(line)
- if value_match
- value = value_match[1]
- value = CGI.unescapeHTML(value)
- value.gsub!('\\\'', '\'')
- value.gsub!('\\"', '"')
- value = convert_placeholders_from_android_to_twine(value)
- value.gsub!(/(\\u0020)*|(\\u0020)*\z/) { |spaces| ' ' * (spaces.length / 6) }
- else
- value = ""
- end
- set_translation_for_key(key, lang, value)
- if comment and comment.length > 0 and !comment.start_with?("SECTION:")
- set_comment_for_key(key, comment)
- end
- comment = nil
- end
-
- comment_match = comment_regex.match(line)
- if comment_match
- comment = comment_match[1]
- end
- end
- end
- end
-
- def format_header(lang)
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Tizen Strings File -->\n<!-- Generated by Twine #{Twine::VERSION} -->\n<!-- Language: #{lang} -->"
- end
-
- def format_sections(twine_file, lang)
- result = '<string_table Bversion="2.0.0.201311071819" Dversion="20120315">'
-
- result += super + "\n"
-
- result += "</string_table>\n"
- end
-
- def format_section_header(section)
- "\t<!-- SECTION: #{section.name} -->"
- end
-
- def format_comment(definition, lang)
- "\t<!-- #{definition.comment.gsub('--', '—')} -->\n" if definition.comment
- end
-
- def key_value_pattern
- "\t<text id=\"IDS_%{key}\">%{value}</text>"
- end
-
- def format_key(key)
- key.upcase
- end
-
- def format_value(value)
- value = escape_quotes(value)
- # Tizen enforces the following rules on the values
- # 1) apostrophes and quotes must be escaped with a backslash
- value.gsub!("'", "\\\\'")
- # 2) HTML escape the string
- value = CGI.escapeHTML(value)
- # 3) fix substitutions (e.g. %s/%@)
- value = convert_placeholders_from_twine_to_android(value)
- # 4) replace beginning and end spaces with \0020. Otherwise Tizen strips them.
- value.gsub(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
- end
- end
- end
-end
-
-Twine::Formatters.formatters << Twine::Formatters::Tizen.new
diff --git a/tools/twine/lib/twine/output_processor.rb b/tools/twine/lib/twine/output_processor.rb
deleted file mode 100644
index 8924ad10a8..0000000000
--- a/tools/twine/lib/twine/output_processor.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-module Twine
- module Processors
-
- class OutputProcessor
- def initialize(twine_file, options)
- @twine_file = twine_file
- @options = options
- end
-
- def default_language
- @options[:developer_language] || @twine_file.language_codes[0]
- end
-
- def fallback_languages(language)
- fallback_mapping = {
- 'zh-TW' => 'zh-Hant' # if we don't have a zh-TW translation, try zh-Hant before en
- }
-
- [fallback_mapping[language], default_language].flatten.compact
- end
-
- def process(language)
- result = TwineFile.new
-
- result.language_codes.concat @twine_file.language_codes
- @twine_file.sections.each do |section|
- new_section = TwineSection.new section.name
-
- section.definitions.each do |definition|
- next unless definition.matches_tags?(@options[:tags], @options[:untagged])
-
- value = definition.translation_for_lang(language)
-
- next if value && @options[:include] == :untranslated
-
- if value.nil? && @options[:include] != :translated
- value = definition.translation_for_lang(fallback_languages(language))
- end
-
- next unless value
-
- new_definition = definition.dup
- new_definition.translations[language] = value
-
- new_section.definitions << new_definition
- result.definitions_by_key[new_definition.key] = new_definition
- end
-
- result.sections << new_section
- end
-
- return result
- end
- end
-
- end
-end
diff --git a/tools/twine/lib/twine/placeholders.rb b/tools/twine/lib/twine/placeholders.rb
deleted file mode 100644
index 5277357da9..0000000000
--- a/tools/twine/lib/twine/placeholders.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-module Twine
- module Placeholders
- extend self
-
- # Note: the ` ` (single space) flag is NOT supported
- PLACEHOLDER_FLAGS_WIDTH_PRECISION_LENGTH = '([-+0#])?(\d+|\*)?(\.(\d+|\*))?(hh?|ll?|L|z|j|t)?'
- PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH = '(\d+\$)?' + PLACEHOLDER_FLAGS_WIDTH_PRECISION_LENGTH
- PLACEHOLDER_TYPES = '[diufFeEgGxXoscpaAq]'
-
- def convert_twine_string_placeholder(input)
- # %@ -> %s
- input.gsub(/(%#{PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH})@/, '\1s')
- end
-
- # http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
- # http://stackoverflow.com/questions/4414389/android-xml-percent-symbol
- # https://github.com/mobiata/twine/pull/106
- def convert_placeholders_from_twine_to_android(input)
- # %@ -> %s
- value = convert_twine_string_placeholder(input)
-
- placeholder_syntax = PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH + PLACEHOLDER_TYPES
- placeholder_regex = /%#{placeholder_syntax}/
-
- number_of_placeholders = value.scan(placeholder_regex).size
-
- return value if number_of_placeholders == 0
-
- # got placeholders -> need to double single percent signs
- # % -> %% (but %% -> %%, %d -> %d)
- single_percent_regex = /([^%])(%)(?!(%|#{placeholder_syntax}))/
- value.gsub! single_percent_regex, '\1%%'
-
- return value if number_of_placeholders < 2
-
- # number placeholders
- non_numbered_placeholder_regex = /%(#{PLACEHOLDER_FLAGS_WIDTH_PRECISION_LENGTH}#{PLACEHOLDER_TYPES})/
-
- number_of_non_numbered_placeholders = value.scan(non_numbered_placeholder_regex).size
-
- return value if number_of_non_numbered_placeholders == 0
-
- raise Twine::Error.new("The value \"#{input}\" contains numbered and non-numbered placeholders") if number_of_placeholders != number_of_non_numbered_placeholders
-
- # %d -> %$1d
- index = 0
- value.gsub!(non_numbered_placeholder_regex) { "%#{index += 1}$#{$1}" }
-
- value
- end
-
- def convert_placeholders_from_android_to_twine(input)
- placeholder_regex = /(%#{PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH})s/
-
- # %s -> %@
- input.gsub(placeholder_regex, '\1@')
- end
-
- # http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/resources/IResourceManager.html#getString()
- # http://soenkerohde.com/2008/07/flex-localization/comment-page-1/
- def convert_placeholders_from_twine_to_flash(input)
- value = convert_twine_string_placeholder(input)
-
- placeholder_regex = /%#{PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH}#{PLACEHOLDER_TYPES}/
- value.gsub(placeholder_regex).each_with_index do |match, index|
- "{#{index}}"
- end
- end
-
- def convert_placeholders_from_flash_to_twine(input)
- input.gsub /\{\d+\}/, '%@'
- end
- end
-end
diff --git a/tools/twine/lib/twine/plugin.rb b/tools/twine/lib/twine/plugin.rb
deleted file mode 100644
index 0967e1ad90..0000000000
--- a/tools/twine/lib/twine/plugin.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require 'safe_yaml/load'
-
-SafeYAML::OPTIONS[:suppress_warnings] = true
-
-module Twine
- class Plugin
- attr_reader :debug, :config
-
- def initialize
- @debug = false
- require_gems
- end
-
- ###
- # require gems from the yaml config.
- #
- # gems: [twine-plugin1, twine-2]
- #
- # also works with single gem
- #
- # gems: twine-plugin1
- #
- def require_gems
- # ./twine.yml # current working directory
- # ~/.twine # home directory
- # /etc/twine.yml # etc
- cwd_config = join_path Dir.pwd, 'twine.yml'
- home_config = join_path Dir.home, '.twine'
- etc_config = '/etc/twine.yml'
-
- config_order = [cwd_config, home_config, etc_config]
-
- puts "Config order: #{config_order}" if debug
-
- config_order.each do |config_file|
- next unless valid_file config_file
- puts "Loading: #{config_file}" if debug
- @config = SafeYAML.load_file config_file
- puts "Config yaml: #{config}" if debug
- break
- end
-
- return unless config
-
- # wrap gems in an array. if nil then array will be empty
- Kernel.Array(config['gems']).each do |gem_path|
- puts "Requiring: #{gem_path}" if debug
- require gem_path
- end
- end
-
- private
-
- def valid_file path
- File.exist?(path) && File.readable?(path) && !File.directory?(path)
- end
-
- def join_path *paths
- File.expand_path File.join *paths
- end
- end
-end
diff --git a/tools/twine/lib/twine/runner.rb b/tools/twine/lib/twine/runner.rb
deleted file mode 100644
index af35370fa5..0000000000
--- a/tools/twine/lib/twine/runner.rb
+++ /dev/null
@@ -1,325 +0,0 @@
-require 'tmpdir'
-require 'fileutils'
-
-Twine::Plugin.new # Initialize plugins first in Runner.
-
-module Twine
- class Runner
- def self.run(args)
- options = CLI.parse(args)
-
- twine_file = TwineFile.new
- twine_file.read options[:twine_file]
- runner = new(options, twine_file)
-
- case options[:command]
- when 'generate-localization-file'
- runner.generate_localization_file
- when 'generate-all-localization-files'
- runner.generate_all_localization_files
- when 'consume-localization-file'
- runner.consume_localization_file
- when 'consume-all-localization-files'
- runner.consume_all_localization_files
- when 'generate-localization-archive'
- runner.generate_localization_archive
- when 'consume-localization-archive'
- runner.consume_localization_archive
- when 'validate-twine-file'
- runner.validate_twine_file
- end
- end
-
- def initialize(options = {}, twine_file = TwineFile.new)
- @options = options
- @twine_file = twine_file
- end
-
- def write_twine_data(path)
- if @options[:developer_language]
- @twine_file.set_developer_language_code(@options[:developer_language])
- end
- @twine_file.write(path)
- end
-
- def generate_localization_file
- validate_twine_file if @options[:validate]
-
- lang = nil
- lang = @options[:languages][0] if @options[:languages]
-
- formatter, lang = prepare_read_write(@options[:output_path], lang)
- output = formatter.format_file(lang)
-
- raise Twine::Error.new "Nothing to generate! The resulting file would not contain any translations." unless output
-
- IO.write(@options[:output_path], output, encoding: output_encoding)
- end
-
- def generate_all_localization_files
- validate_twine_file if @options[:validate]
-
- if !File.directory?(@options[:output_path])
- if @options[:create_folders]
- FileUtils.mkdir_p(@options[:output_path])
- else
- raise Twine::Error.new("Directory does not exist: #{@options[:output_path]}")
- end
- end
-
- formatter_for_directory = find_formatter { |f| f.can_handle_directory?(@options[:output_path]) }
- formatter = formatter_for_format(@options[:format]) || formatter_for_directory
-
- unless formatter
- raise Twine::Error.new "Could not determine format given the contents of #{@options[:output_path]}"
- end
-
- file_name = @options[:file_name] || formatter.default_file_name
- if @options[:create_folders]
- @twine_file.language_codes.each do |lang|
- output_path = File.join(@options[:output_path], formatter.output_path_for_language(lang))
-
- FileUtils.mkdir_p(output_path)
-
- file_path = File.join(output_path, file_name)
-
- output = formatter.format_file(lang)
- unless output
- Twine::stderr.puts "Skipping file at path #{file_path} since it would not contain any translations."
- next
- end
-
- IO.write(file_path, output, encoding: output_encoding)
- end
- else
- language_found = false
- Dir.foreach(@options[:output_path]) do |item|
- next if item == "." or item == ".."
-
- output_path = File.join(@options[:output_path], item)
- next unless File.directory?(output_path)
-
- lang = formatter.determine_language_given_path(output_path)
- next unless lang
-
- language_found = true
-
- file_path = File.join(output_path, file_name)
- output = formatter.format_file(lang)
- unless output
- Twine::stderr.puts "Skipping file at path #{file_path} since it would not contain any translations."
- next
- end
-
- IO.write(file_path, output, encoding: output_encoding)
- end
-
- unless language_found
- raise Twine::Error.new("Failed to generate any files: No languages found at #{@options[:output_path]}")
- end
- end
-
- end
-
- def generate_localization_archive
- validate_twine_file if @options[:validate]
-
- require_rubyzip
-
- if File.file?(@options[:output_path])
- File.delete(@options[:output_path])
- end
-
- Dir.mktmpdir do |temp_dir|
- Zip::File.open(@options[:output_path], Zip::File::CREATE) do |zipfile|
- zipfile.mkdir('Locales')
-
- formatter = formatter_for_format(@options[:format])
- @twine_file.language_codes.each do |lang|
- if @options[:languages] == nil || @options[:languages].length == 0 || @options[:languages].include?(lang)
- file_name = lang + formatter.extension
- temp_path = File.join(temp_dir, file_name)
- zip_path = File.join('Locales', file_name)
-
- output = formatter.format_file(lang)
- unless output
- Twine::stderr.puts "Skipping file #{file_name} since it would not contain any translations."
- next
- end
-
- IO.write(temp_path, output, encoding: output_encoding)
- zipfile.add(zip_path, temp_path)
- end
- end
- end
- end
- end
-
- def consume_localization_file
- lang = nil
- if @options[:languages]
- lang = @options[:languages][0]
- end
-
- read_localization_file(@options[:input_path], lang)
- output_path = @options[:output_path] || @options[:twine_file]
- write_twine_data(output_path)
- end
-
- def consume_all_localization_files
- if !File.directory?(@options[:input_path])
- raise Twine::Error.new("Directory does not exist: #{@options[:input_path]}")
- end
-
- Dir.glob(File.join(@options[:input_path], "**/*")) do |item|
- if File.file?(item)
- begin
- read_localization_file(item)
- rescue Twine::Error => e
- Twine::stderr.puts "#{e.message}"
- end
- end
- end
-
- output_path = @options[:output_path] || @options[:twine_file]
- write_twine_data(output_path)
- end
-
- def consume_localization_archive
- require_rubyzip
-
- if !File.file?(@options[:input_path])
- raise Twine::Error.new("File does not exist: #{@options[:input_path]}")
- end
-
- Dir.mktmpdir do |temp_dir|
- Zip::File.open(@options[:input_path]) do |zipfile|
- zipfile.each do |entry|
- next if entry.name.end_with? '/' or File.basename(entry.name).start_with? '.'
-
- real_path = File.join(temp_dir, entry.name)
- FileUtils.mkdir_p(File.dirname(real_path))
- zipfile.extract(entry.name, real_path)
- begin
- read_localization_file(real_path)
- rescue Twine::Error => e
- Twine::stderr.puts "#{e.message}"
- end
- end
- end
- end
-
- output_path = @options[:output_path] || @options[:twine_file]
- write_twine_data(output_path)
- end
-
- def validate_twine_file
- total_definitions = 0
- all_keys = Set.new
- duplicate_keys = Set.new
- keys_without_tags = Set.new
- invalid_keys = Set.new
- valid_key_regex = /^[A-Za-z0-9_]+$/
-
- @twine_file.sections.each do |section|
- section.definitions.each do |definition|
- total_definitions += 1
-
- duplicate_keys.add(definition.key) if all_keys.include? definition.key
- all_keys.add(definition.key)
-
- keys_without_tags.add(definition.key) if definition.tags == nil or definition.tags.length == 0
-
- invalid_keys << definition.key unless definition.key =~ valid_key_regex
- end
- end
-
- errors = []
- join_keys = lambda { |set| set.map { |k| " " + k }.join("\n") }
-
- unless duplicate_keys.empty?
- errors << "Found duplicate key(s):\n#{join_keys.call(duplicate_keys)}"
- end
-
- if @options[:pedantic]
- if keys_without_tags.length == total_definitions
- errors << "None of your definitions have tags."
- elsif keys_without_tags.length > 0
- errors << "Found definitions without tags:\n#{join_keys.call(keys_without_tags)}"
- end
- end
-
- unless invalid_keys.empty?
- errors << "Found key(s) with invalid characters:\n#{join_keys.call(invalid_keys)}"
- end
-
- raise Twine::Error.new errors.join("\n\n") unless errors.empty?
-
- Twine::stdout.puts "#{@options[:twine_file]} is valid."
- end
-
- private
-
- def output_encoding
- @options[:encoding] || 'UTF-8'
- end
-
- def require_rubyzip
- begin
- require 'zip'
- rescue LoadError
- raise Twine::Error.new "You must run 'gem install rubyzip' in order to create or consume localization archives."
- end
- end
-
- def determine_language_given_path(path)
- code = File.basename(path, File.extname(path))
- return code if @twine_file.language_codes.include? code
- end
-
- def formatter_for_format(format)
- find_formatter { |f| f.format_name == format }
- end
-
- def find_formatter(&block)
- formatter = Formatters.formatters.find &block
- return nil unless formatter
- formatter.twine_file = @twine_file
- formatter.options = @options
- formatter
- end
-
- def read_localization_file(path, lang = nil)
- unless File.file?(path)
- raise Twine::Error.new("File does not exist: #{path}")
- end
-
- formatter, lang = prepare_read_write(path, lang)
-
- external_encoding = @options[:encoding] || Twine::Encoding.encoding_for_path(path)
-
- IO.open(IO.sysopen(path, 'rb'), 'rb', external_encoding: external_encoding, internal_encoding: 'UTF-8') do |io|
- io.read(2) if Twine::Encoding.has_bom?(path)
- formatter.read(io, lang)
- end
- end
-
- def prepare_read_write(path, lang)
- formatter_for_path = find_formatter { |f| f.extension == File.extname(path) }
- formatter = formatter_for_format(@options[:format]) || formatter_for_path
-
- unless formatter
- raise Twine::Error.new "Unable to determine format of #{path}"
- end
-
- lang = lang || determine_language_given_path(path) || formatter.determine_language_given_path(path)
- unless lang
- raise Twine::Error.new "Unable to determine language for #{path}"
- end
-
- @twine_file.language_codes << lang unless @twine_file.language_codes.include? lang
-
- return formatter, lang
- end
- end
-end
diff --git a/tools/twine/lib/twine/stringsfile.rb b/tools/twine/lib/twine/stringsfile.rb
deleted file mode 100644
index 9de932c228..0000000000
--- a/tools/twine/lib/twine/stringsfile.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-module Twine
- class StringsSection
- attr_reader :name
- attr_reader :rows
-
- def initialize(name)
- @name = name
- @rows = []
- end
- end
-
- class StringsRow
- attr_reader :key
- attr_accessor :comment
- attr_accessor :tags
- attr_reader :translations
-
- def initialize(key)
- @key = key
- @comment = nil
- @tags = nil
- @translations = {}
- end
-
- def matches_tags?(tags, include_untagged)
- if tags == nil || tags.length == 0
- # The user did not specify any tags. Everything passes.
- return true
- elsif @tags == nil || @tags.length == 0
- # This row has no tags.
- return (include_untagged) ? true : false
- else
- tags.each do |tag|
- if @tags.include? tag
- return true
- end
- end
- end
-
- return false
- end
-
- def translated_string_for_lang(lang, default_lang=nil)
- if @translations[lang]
- return @translations[lang]
- elsif default_lang.respond_to?("each")
- default_lang.each do |def_lang|
- if @translations[def_lang]
- return @translations[def_lang]
- end
- end
- return nil
- else
- return @translations[default_lang]
- end
- end
- end
-
- class StringsFile
- attr_reader :sections
- attr_reader :strings_map
- attr_reader :language_codes
-
- def initialize
- @sections = []
- @strings_map = {}
- @language_codes = []
- end
-
- def read(path)
- if !File.file?(path)
- raise Twine::Error.new("File does not exist: #{path}")
- end
-
- File.open(path, 'r:UTF-8') do |f|
- line_num = 0
- current_section = nil
- current_row = nil
- while line = f.gets
- parsed = false
- line.strip!
- line_num += 1
-
- if line.length == 0
- next
- end
-
- if line.length > 4 && line[0, 2] == '[['
- match = /^\[\[(.+)\]\]$/.match(line)
- if match
- current_section = StringsSection.new(match[1])
- @sections << current_section
- parsed = true
- end
- elsif line.length > 2 && line[0, 1] == '['
- match = /^\[(.+)\]$/.match(line)
- if match
- current_row = StringsRow.new(match[1])
- @strings_map[current_row.key] = current_row
- if !current_section
- current_section = StringsSection.new('')
- @sections << current_section
- end
- current_section.rows << current_row
- parsed = true
- end
- else
- match = /^([^=]+)=(.*)$/.match(line)
- if match
- key = match[1].strip
- value = match[2].strip
- if value[0,1] == '`' && value[-1,1] == '`'
- value = value[1..-2]
- end
-
- case key
- when "comment"
- current_row.comment = value
- when 'tags'
- current_row.tags = value.split(',')
- else
- if !@language_codes.include? key
- add_language_code(key)
- end
- current_row.translations[key] = value
- end
- parsed = true
- end
- end
-
- if !parsed
- raise Twine::Error.new("Unable to parse line #{line_num} of #{path}: #{line}")
- end
- end
- end
- end
-
- def write(path)
- dev_lang = @language_codes[0]
-
- File.open(path, 'w:UTF-8') do |f|
- @sections.each do |section|
- if f.pos > 0
- f.puts ''
- end
-
- f.puts "[[#{section.name}]]"
-
- section.rows.each do |row|
- f.puts "\t[#{row.key}]"
- value = row.translations[dev_lang]
- if !value
- puts "Warning: #{row.key} does not exist in developer language '#{dev_lang}'"
- else
- if value[0,1] == ' ' || value[-1,1] == ' ' || (value[0,1] == '`' && value[-1,1] == '`')
- value = '`' + value + '`'
- end
- f.puts "\t\t#{dev_lang} = #{value}"
- end
-
- if row.tags && row.tags.length > 0
- tag_str = row.tags.join(',')
- f.puts "\t\ttags = #{tag_str}"
- end
- if row.comment && row.comment.length > 0
- f.puts "\t\tcomment = #{row.comment}"
- end
- @language_codes[1..-1].each do |lang|
- value = row.translations[lang]
- if value
- if value[0,1] == ' ' || value[-1,1] == ' ' || (value[0,1] == '`' && value[-1,1] == '`')
- value = '`' + value + '`'
- end
- f.puts "\t\t#{lang} = #{value}"
- end
- end
- end
- end
- end
- end
-
- def add_language_code(code)
- if @language_codes.length == 0
- @language_codes << code
- elsif !@language_codes.include?(code)
- dev_lang = @language_codes[0]
- @language_codes << code
- @language_codes.delete(dev_lang)
- @language_codes.sort!
- @language_codes.insert(0, dev_lang)
- end
- end
-
- def set_developer_language_code(code)
- if @language_codes.include?(code)
- @language_codes.delete(code)
- end
- @language_codes.insert(0, code)
- end
- end
-end
diff --git a/tools/twine/lib/twine/twine_file.rb b/tools/twine/lib/twine/twine_file.rb
deleted file mode 100644
index b000180d59..0000000000
--- a/tools/twine/lib/twine/twine_file.rb
+++ /dev/null
@@ -1,229 +0,0 @@
-module Twine
- class TwineDefinition
- attr_reader :key
- attr_accessor :comment
- attr_accessor :tags
- attr_reader :translations
- attr_accessor :reference
- attr_accessor :reference_key
-
- def initialize(key)
- @key = key
- @comment = nil
- @tags = nil
- @translations = {}
- end
-
- def comment
- raw_comment || (reference.comment if reference)
- end
-
- def raw_comment
- @comment
- end
-
- # [['tag1', 'tag2'], ['~tag3']] == (tag1 OR tag2) AND (!tag3)
- def matches_tags?(tags, include_untagged)
- if tags == nil || tags.empty? # The user did not specify any tags. Everything passes.
- return true
- elsif @tags == nil # This definition has no tags -> check reference (if any)
- return reference ? reference.matches_tags?(tags, include_untagged) : include_untagged
- elsif @tags.empty?
- return include_untagged
- else
- return tags.all? do |set|
- regular_tags, negated_tags = set.partition { |tag| tag[0] != '~' }
- negated_tags.map! { |tag| tag[1..-1] }
- matches_regular_tags = (!regular_tags.empty? && !(regular_tags & @tags).empty?)
- matches_negated_tags = (!negated_tags.empty? && (negated_tags & @tags).empty?)
- matches_regular_tags or matches_negated_tags
- end
- end
-
- return false
- end
-
- def translation_for_lang(lang)
- translation = [lang].flatten.map { |l| @translations[l] }.first
-
- translation = reference.translation_for_lang(lang) if translation.nil? && reference
-
- return translation
- end
- end
-
- class TwineSection
- attr_reader :name
- attr_reader :definitions
-
- def initialize(name)
- @name = name
- @definitions = []
- end
- end
-
- class TwineFile
- attr_reader :sections
- attr_reader :definitions_by_key
- attr_reader :language_codes
-
- private
-
- def match_key(text)
- match = /^\[(.+)\]$/.match(text)
- return match[1] if match
- end
-
- public
-
- def initialize
- @sections = []
- @definitions_by_key = {}
- @language_codes = []
- end
-
- def add_language_code(code)
- if @language_codes.length == 0
- @language_codes << code
- elsif !@language_codes.include?(code)
- dev_lang = @language_codes[0]
- @language_codes << code
- @language_codes.delete(dev_lang)
- @language_codes.sort!
- @language_codes.insert(0, dev_lang)
- end
- end
-
- def set_developer_language_code(code)
- @language_codes.delete(code)
- @language_codes.insert(0, code)
- end
-
- def read(path)
- if !File.file?(path)
- raise Twine::Error.new("File does not exist: #{path}")
- end
-
- File.open(path, 'r:UTF-8') do |f|
- line_num = 0
- current_section = nil
- current_definition = nil
- while line = f.gets
- parsed = false
- line.strip!
- line_num += 1
-
- if line.length == 0
- next
- end
-
- if line.length > 4 && line[0, 2] == '[['
- match = /^\[\[(.+)\]\]$/.match(line)
- if match
- current_section = TwineSection.new(match[1])
- @sections << current_section
- parsed = true
- end
- elsif line.length > 2 && line[0, 1] == '['
- key = match_key(line)
- if key
- current_definition = TwineDefinition.new(key)
- @definitions_by_key[current_definition.key] = current_definition
- if !current_section
- current_section = TwineSection.new('')
- @sections << current_section
- end
- current_section.definitions << current_definition
- parsed = true
- end
- else
- match = /^([^=]+)=(.*)$/.match(line)
- if match
- key = match[1].strip
- value = match[2].strip
-
- value = value[1..-2] if value[0] == '`' && value[-1] == '`'
-
- case key
- when 'comment'
- current_definition.comment = value
- when 'tags'
- current_definition.tags = value.split(',')
- when 'ref'
- current_definition.reference_key = value if value
- else
- if !@language_codes.include? key
- add_language_code(key)
- end
- current_definition.translations[key] = value
- end
- parsed = true
- end
- end
-
- if !parsed
- raise Twine::Error.new("Unable to parse line #{line_num} of #{path}: #{line}")
- end
- end
- end
-
- # resolve_references
- @definitions_by_key.each do |key, definition|
- next unless definition.reference_key
- definition.reference = @definitions_by_key[definition.reference_key]
- end
- end
-
- def write(path)
- dev_lang = @language_codes[0]
-
- File.open(path, 'w:UTF-8') do |f|
- @sections.each do |section|
- if f.pos > 0
- f.puts ''
- end
-
- f.puts "[[#{section.name}]]"
-
- section.definitions.each do |definition|
- f.puts "\t[#{definition.key}]"
-
- value = write_value(definition, dev_lang, f)
- if !value && !definition.reference_key
- puts "Warning: #{definition.key} does not exist in developer language '#{dev_lang}'"
- end
-
- if definition.reference_key
- f.puts "\t\tref = #{definition.reference_key}"
- end
- if definition.tags && definition.tags.length > 0
- tag_str = definition.tags.join(',')
- f.puts "\t\ttags = #{tag_str}"
- end
- if definition.raw_comment and definition.raw_comment.length > 0
- f.puts "\t\tcomment = #{definition.raw_comment}"
- end
- @language_codes[1..-1].each do |lang|
- write_value(definition, lang, f)
- end
- end
- end
- end
- end
-
- private
-
- def write_value(definition, language, file)
- value = definition.translations[language]
- return nil unless value
-
- if value[0] == ' ' || value[-1] == ' ' || (value[0] == '`' && value[-1] == '`')
- value = '`' + value + '`'
- end
-
- file.puts "\t\t#{language} = #{value}"
- return value
- end
-
- end
-end
diff --git a/tools/twine/lib/twine/version.rb b/tools/twine/lib/twine/version.rb
deleted file mode 100644
index d289a0ce10..0000000000
--- a/tools/twine/lib/twine/version.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-module Twine
- VERSION = '0.10.1'
-end
diff --git a/tools/twine/twine b/tools/twine/twine
deleted file mode 100755
index fc9aa6eecf..0000000000
--- a/tools/twine/twine
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-BASEDIR=$(dirname $0)
-ruby -rubygems -I $BASEDIR/lib $BASEDIR/bin/twine $@
diff --git a/tools/twine/twine.gemspec b/tools/twine/twine.gemspec
deleted file mode 100644
index d16d04bca6..0000000000
--- a/tools/twine/twine.gemspec
+++ /dev/null
@@ -1,34 +0,0 @@
-$LOAD_PATH.unshift 'lib'
-require 'twine/version'
-
-Gem::Specification.new do |s|
- s.name = "twine"
- s.version = Twine::VERSION
- s.date = Time.now.strftime('%Y-%m-%d')
- s.summary = "Manage strings and their translations for your iOS, Android and other projects."
- s.homepage = "https://github.com/mobiata/twine"
- s.email = "twine@mobiata.com"
- s.authors = [ "Sebastian Celis" ]
- s.has_rdoc = false
- s.license = "BSD-3-Clause"
-
- s.files = %w( Gemfile README.md LICENSE )
- s.files += Dir.glob("lib/**/*")
- s.files += Dir.glob("bin/**/*")
- s.files += Dir.glob("test/**/*")
- s.test_files = Dir.glob("test/test_*")
-
- s.required_ruby_version = ">= 2.0"
- s.add_runtime_dependency('rubyzip', "~> 1.1")
- s.add_runtime_dependency('safe_yaml', "~> 1.0")
- s.add_development_dependency('rake', "~> 10.4")
- s.add_development_dependency('minitest', "~> 5.5")
- s.add_development_dependency('mocha', "~> 1.1")
-
- s.executables = %w( twine )
- s.description = <<desc
- Twine is a command line tool for managing your strings and their translations.
-
- It is geared toward Mac OS X, iOS, and Android developers.
-desc
-end