terrestrial-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +134 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/bin/terrestrial +44 -0
  13. data/circle.yml +11 -0
  14. data/lib/terrestrial/cli/android_xml_formatter.rb +43 -0
  15. data/lib/terrestrial/cli/android_xml_parser.rb +49 -0
  16. data/lib/terrestrial/cli/bootstrapper.rb +184 -0
  17. data/lib/terrestrial/cli/command.rb +20 -0
  18. data/lib/terrestrial/cli/detects_project_type.rb +16 -0
  19. data/lib/terrestrial/cli/dot_strings_formatter.rb +53 -0
  20. data/lib/terrestrial/cli/dot_strings_parser.rb +139 -0
  21. data/lib/terrestrial/cli/editor/android_xml.rb +64 -0
  22. data/lib/terrestrial/cli/editor/base_editor.rb +36 -0
  23. data/lib/terrestrial/cli/editor/objc.rb +66 -0
  24. data/lib/terrestrial/cli/editor/printer.rb +47 -0
  25. data/lib/terrestrial/cli/editor/storyboard.rb +98 -0
  26. data/lib/terrestrial/cli/editor/swift.rb +92 -0
  27. data/lib/terrestrial/cli/editor.rb +42 -0
  28. data/lib/terrestrial/cli/engine_mapper.rb +30 -0
  29. data/lib/terrestrial/cli/entry_collection_differ.rb +22 -0
  30. data/lib/terrestrial/cli/file_finder.rb +65 -0
  31. data/lib/terrestrial/cli/file_picker.rb +58 -0
  32. data/lib/terrestrial/cli/flight/ios_workflow.rb +81 -0
  33. data/lib/terrestrial/cli/flight/table_workflow.rb +77 -0
  34. data/lib/terrestrial/cli/flight.rb +93 -0
  35. data/lib/terrestrial/cli/ignite.rb +73 -0
  36. data/lib/terrestrial/cli/init.rb +133 -0
  37. data/lib/terrestrial/cli/mixpanel_client.rb +56 -0
  38. data/lib/terrestrial/cli/parser/android_xml.rb +82 -0
  39. data/lib/terrestrial/cli/parser/base_parser.rb +42 -0
  40. data/lib/terrestrial/cli/parser/objc.rb +127 -0
  41. data/lib/terrestrial/cli/parser/storyboard.rb +166 -0
  42. data/lib/terrestrial/cli/parser/string_analyser.rb +115 -0
  43. data/lib/terrestrial/cli/parser/swift.rb +102 -0
  44. data/lib/terrestrial/cli/parser.rb +25 -0
  45. data/lib/terrestrial/cli/photoshoot.rb +65 -0
  46. data/lib/terrestrial/cli/pull.rb +110 -0
  47. data/lib/terrestrial/cli/push.rb +40 -0
  48. data/lib/terrestrial/cli/scan.rb +72 -0
  49. data/lib/terrestrial/cli/string_registry.rb +30 -0
  50. data/lib/terrestrial/cli/terminal_ui.rb +25 -0
  51. data/lib/terrestrial/cli/variable_normalizer.rb +34 -0
  52. data/lib/terrestrial/cli/version.rb +5 -0
  53. data/lib/terrestrial/cli.rb +82 -0
  54. data/lib/terrestrial/config.rb +99 -0
  55. data/lib/terrestrial/creates_terrestrial_yml.rb +9 -0
  56. data/lib/terrestrial/web/response.rb +17 -0
  57. data/lib/terrestrial/web.rb +78 -0
  58. data/lib/terrestrial/yaml_helper.rb +48 -0
  59. data/lib/terrestrial.rb +7 -0
  60. data/terrestrial-cli.gemspec +29 -0
  61. metadata +188 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e281351eb1f04aa6331e79dcb3c229569c7886be
4
+ data.tar.gz: 782805e8aafda3c9fbc1af5120b59b969b7f800c
5
+ SHA512:
6
+ metadata.gz: 791442b2416b61b88c2ee69daee39a8c25600e5b74f3ff2a1a74cc86a5f25326452a8c175224ec80365ee02219d15892f26cf5b74c614c6c942701f5ef742419
7
+ data.tar.gz: eec81b09adaa373bcef0ce1ee419721a0fe40091d61c9b8270443fd7f2a7b7e297e611d794474f9491b7bb6b0062491511167696ffead0c8b6a80a3695cfb919
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ terrestrial-cli
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p648
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in terrestrial-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Niklas Begley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # Terrestrial::Cli
2
+
3
+ Official Terrestrial command line tool. For more documentation visit the [official docs](http://docs.terrestrial.io/).
4
+
5
+ If you have any questions, join us on [Slack](https://terrestrial-slack.herokuapp.com/)!
6
+
7
+ ## Installation
8
+
9
+ $ gem install terrestrial-cli
10
+
11
+ ## Usage
12
+
13
+ To get started with your project, cd to your project directory and run
14
+
15
+ $ terrestrial init --api-key <API KEY> --project-id <PROJECT ID>
16
+
17
+ You can find your API key and the correct project ID by logging into [Terrestrial Mission Control](https://mission.terrestrial.io).
18
+
19
+ ### First time localizing
20
+
21
+ If you have not internationalized your app before, Terrestrial provides a tool for quickly extracting user-facing strings from your source code:
22
+
23
+ $ terrestrial flight
24
+
25
+ ##### iOS
26
+
27
+ Flight will scan your source code and, using some clever heuristics, determine which strings can be shown to users. Terrestrial will list all the strings in terminal, and you are able to exclude any strings you wish not to internationalize.
28
+
29
+ ...
30
+ Page 5 of 5
31
+ +-------+------------------------------+------------------------------------------------+
32
+ | Index | String | File |
33
+ +-------+------------------------------+------------------------------------------------+
34
+ | 40 | Home | InspectionMadeEasy/LeftMenuViewController.m:96 |
35
+ +-------+------------------------------+------------------------------------------------+
36
+ | 41 | Home | InspectionMadeEasy/MainViewController.m:23 |
37
+ +-------+------------------------------+------------------------------------------------+
38
+ -- Instructions --
39
+ - To exclude any strings from translation, type the index of each string.
40
+ - e.g. 1,2,4
41
+ ------------------
42
+ Any Exclusions? (press return to continue or 'q' to quit at any time)
43
+
44
+ $
45
+
46
+ After this, Terrestrial generates a **Base.lproj/Localizable.strings** file based on the selected strings, and updates your source code so that each occurence of each strings is properly referenced by ID:
47
+
48
+ # Source Code
49
+ label.text = @"This is my string" => label.text = @"THIS_IS_MY_STRING".translated
50
+
51
+ # The ID is generated based on the original string.
52
+ # The .translated method is simple syntactic sugar over NSLocalizedString, and you
53
+ # are able to fall back to native iOS localization APIs if needed.
54
+
55
+ **Note on Stroyboards:** Terrestrial allows you to easily use strings from your Localizable.strings files inside your Storyboards via IBInspectable properties. During the *flight* process, any strings in Storyboards will have the Terrestrial IBInspectable property turned on, and the string's ID included as a value in the properties. To see this in action, view the Attributed Inspector tab of a UI element in your Storyboards.
56
+
57
+ #### Android
58
+
59
+ ** Documentation coming soon **
60
+
61
+ ### Existing App
62
+
63
+ If you have already translated your application, Terrestrial needs to know where to find your translation files. This is done via the **terrestrial.yml** file created when your project is initialized:
64
+
65
+ ---
66
+ app_id: <app ID>
67
+ project_id: <project ID>
68
+ platform: <platform>
69
+ translation_files:
70
+ - /path/to
71
+ - /any/localization/files
72
+
73
+ Terrestrial will keep of the strings listed in the listed files.
74
+
75
+ ### Workflow
76
+
77
+ As you add strings to you app, either in iOS's Localizable.strings or Android's strings.xml, you can track your changes with:
78
+
79
+ $ terrestrial scan
80
+ New Strings: 0
81
+ Removed Strings: 0
82
+
83
+ This will diff your local strings with the current strings stored in Terrestrial. You can see a breakdown of changes by running:
84
+
85
+ $ terrestrial scan --verbose
86
+
87
+ When you are ready to upload your local changes with Terrestrial for your translators to get to work, push your latest strings to Terrestrial:
88
+
89
+ $ terrestrial push
90
+
91
+ We suggest running *push* as part of a standard build cycle.
92
+
93
+ To get the latest translations for your app, run:
94
+
95
+ $ terrestrial pull
96
+
97
+ This will update the necessary language files in your project automatically with updated translations.
98
+
99
+ ### Testing
100
+
101
+ Terrestrial allows you to start your iOS simulator in a specified locale from the command line:
102
+
103
+ $ terrestrial ignite es # Starts the simulator in Spanish
104
+
105
+
106
+ To upload screenshots, along with metadata of string positions and styles, run the photoshoot command:
107
+
108
+ $ terrestrial photoshoot
109
+
110
+ This will start the simulator and initialize the Terrestrial SDK in photoshoot mode. To upload screenshots to your web dashboard, just tap the injected screenshot button for each screen you wish to upload.
111
+
112
+
113
+ ## Contributing
114
+
115
+ Bug reports and pull requests are welcome on GitHub at https://github.com/terrestrial-io/terrestrial-cli.
116
+
117
+ ## Development
118
+
119
+ To run the gem in development, run
120
+
121
+ ruby -Ilib bin/terrestrial <COMMAND>
122
+
123
+ To build the gem and install it in your current Gemset, run
124
+
125
+ rake build
126
+
127
+ To run tests
128
+
129
+ rspec
130
+
131
+ ## License
132
+
133
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
134
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "terrestrial/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/terrestrial ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'terrestrial'
4
+ require 'optparse'
5
+
6
+ command = ARGV[0]
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: terrestrial <command> <options>"
11
+ opts.separator ""
12
+ opts.separator "Commands"
13
+ opts.separator " init Initialize your project with Terrestrial."
14
+ opts.separator " scan Detect any new or deleted strings in your app."
15
+ opts.separator " push Upload the latest strings from your app."
16
+ opts.separator " pull Download latest translations and generate relevant localization files."
17
+ opts.separator " flight (iOS only) Find human facing strings in your app that are not currently set for translation."
18
+ opts.separator " ignite <locale> (iOS only) Start the simulator in a specific locale."
19
+ opts.separator " photoshoot (iOS only) Start the simulator in photoshoot mode."
20
+ opts.separator ""
21
+ opts.separator "Options"
22
+
23
+ opts.on("--api-key [string]", "Set and store api key") do |key|
24
+ options[:api_key] = key
25
+ end
26
+
27
+ opts.on("--project-id [integer]", "Set the app's project id") do |id|
28
+ options[:project_id] = id.to_i
29
+ end
30
+
31
+ opts.on("--verbose [boolean]", "Show additional information related to the command") do |bool|
32
+ options[:verbose] = true
33
+ end
34
+
35
+ opts.on_tail("--version", "Show version") do
36
+ puts "Terrestrial CLI: #{Terrestrial::Cli::VERSION}"
37
+ exit
38
+ end
39
+ end.parse!
40
+
41
+ abort "Terrestrial CLI #{Terrestrial::Cli::VERSION}" if command.nil?
42
+ abort "Terrestrial: '#{command}' does not compute?" unless Terrestrial::Cli::COMMANDS.include? command
43
+
44
+ Terrestrial::Cli.start(command, options, ARGV[1..-1])
data/circle.yml ADDED
@@ -0,0 +1,11 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0
4
+
5
+ dependencies:
6
+ pre:
7
+ - gem update bundler
8
+
9
+ test:
10
+ override:
11
+ - bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
@@ -0,0 +1,43 @@
1
+ require 'rexml/document'
2
+
3
+ module Terrestrial
4
+ module Cli
5
+ class AndroidXmlFormatter
6
+
7
+ def initialize(entries)
8
+ @entries = entries
9
+ end
10
+
11
+ def format_foreign_translation
12
+ root = REXML::Element.new("resources")
13
+
14
+ entries.each do |entry|
15
+ root.add_element("string", {
16
+ "name" => entry.identifier
17
+ }).add_text(entry.string)
18
+ end
19
+
20
+ print_xml(root)
21
+ end
22
+
23
+ def print_xml(document)
24
+ # In which we wrestle with REXML's insanity
25
+
26
+ REXML::Attribute.class_eval( %q^
27
+ def to_string
28
+ %Q[#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"]
29
+ end
30
+ ^)
31
+ formatter = Printer.new(4) # See editor/printer
32
+ formatter.compact = true
33
+ formatter.write(document,"") + "\n"
34
+ end
35
+
36
+ private
37
+
38
+ def entries
39
+ @entries
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ module Terrestrial
2
+ module Cli
3
+ class AndroidXmlParser
4
+
5
+ def self.parse_file(file)
6
+ new(file).parse
7
+ end
8
+
9
+ def initialize(file)
10
+ @path = file
11
+ @file = File.new(file)
12
+ @document = REXML::Document.new(@file)
13
+ end
14
+
15
+ def parse
16
+ result = []
17
+ REXML::XPath.each(@document, "//resources/string[not(@terrestrial='false')]") do |node|
18
+ result << build_entry(node)
19
+ end
20
+ result
21
+ end
22
+
23
+ def build_entry(node)
24
+ Hash.new.tap do |entry|
25
+ entry["file"] = @path
26
+ entry["string"] = get_string_from_node(node)
27
+ entry["type"] = "strings.xml"
28
+ entry["identifier"] = node.attributes["name"]
29
+ end
30
+ end
31
+
32
+ def get_string_from_node(node)
33
+ # Why could the text be nil?
34
+ # - If it contains valid XML!
35
+ #
36
+ # We assume anything inside the string tag is actually
37
+ # what should be shown in the UI, so we just parse it
38
+ # as a string if we realise that the parser thinks it
39
+ # is XML.
40
+
41
+ if !node.get_text.nil?
42
+ node.get_text.value
43
+ else
44
+ node.children.first.to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,184 @@
1
+ require 'delegate'
2
+
3
+ module Terrestrial
4
+ module Cli
5
+ class Bootstrapper
6
+
7
+ def self.find_new_strings(directory)
8
+ result = Result.new
9
+ entries = FileFinder.find(directory, EngineMapper::PARSERS.keys)
10
+ .flat_map {|file| Parser.find_strings(file) }
11
+ .reject {|entry| entry["string"] == "" }
12
+ .select {|entry| Parser::StringAnalyser.is_string_for_humans?(
13
+ entry["string"], entry["language"], entry["variables"])}
14
+
15
+ entries.each do |entry|
16
+ result.add(entry)
17
+ end
18
+ result
19
+ end
20
+ end
21
+
22
+ class Bootstrapper
23
+ class Result
24
+ include Enumerable
25
+
26
+ def initialize
27
+ @result_index = 0
28
+ end
29
+
30
+ def each(&block)
31
+ entries.each do |entry|
32
+ block.call(entry)
33
+ end
34
+ end
35
+
36
+ def each_occurence(&block)
37
+ entries.flat_map(&:as_separate_occurences).each do |entry|
38
+ block.call(entry)
39
+ end
40
+ end
41
+
42
+ def all_occurences
43
+ entries.flat_map(&:as_separate_occurences)
44
+ end
45
+
46
+ def add(entry_hash)
47
+ match = entries.detect {|e| e.string == entry_hash["string"] }
48
+ if match
49
+ match.add_occurence(entry_hash, next_result_index)
50
+ else
51
+ entries << Entry.from_hash(entry_hash, next_result_index)
52
+ end
53
+ end
54
+
55
+ def exclude_occurences(indexes)
56
+ entries.each do |entry|
57
+ entry.occurences.delete_if {|occurence| indexes.include? occurence.result_index }
58
+ end
59
+ end
60
+
61
+ def length
62
+ entries.length
63
+ end
64
+
65
+ def [](i)
66
+ entries[i]
67
+ end
68
+
69
+ def entries
70
+ @entries ||= []
71
+ end
72
+
73
+ private
74
+
75
+ def next_result_index
76
+ @result_index += 1
77
+ @result_index - 1
78
+ end
79
+ end
80
+ end
81
+
82
+ class Bootstrapper
83
+ class Entry
84
+ MAX_IDENTIFIER_LENGTH = 10 # words
85
+
86
+ def initialize(string, occurences = [])
87
+ @string = string
88
+ @occurences = occurences
89
+ end
90
+
91
+ def formatted_string
92
+ if occurences.any? {|occ| occ.language == :swift}
93
+ VariableNormalizer.run(string, swift: true)
94
+ else
95
+ VariableNormalizer.run(string)
96
+ end
97
+ end
98
+
99
+ def self.from_hash(hash, index)
100
+ string = hash.fetch("string")
101
+ occurence = Occurence.from_hash(hash, index)
102
+
103
+ new(string, [occurence])
104
+ end
105
+
106
+ def identifier
107
+ formatted_string
108
+ .gsub(/%\d\$@/, '')
109
+ .gsub(/[^0-9a-z ]/i, '')
110
+ .split(" ")[0..(MAX_IDENTIFIER_LENGTH - 1)]
111
+ .join("_")
112
+ .upcase
113
+ end
114
+
115
+ def string
116
+ @string
117
+ end
118
+
119
+ def occurences
120
+ @occurences
121
+ end
122
+
123
+ def as_separate_occurences
124
+ occurences.map do |occurence|
125
+ EntryOccurence.new(occurence).tap do |occ|
126
+ occ.string = self.string
127
+ occ.identifier = self.identifier
128
+ end
129
+ end
130
+ end
131
+
132
+ def add_occurence(hash, index)
133
+ if hash.fetch("string") == self.string
134
+ @occurences << Occurence.from_hash(hash, index)
135
+ else
136
+ raise "Add non-matching string '#{hash.fetch("string")}' as an occurence to #{self.inspect}"
137
+ end
138
+ end
139
+
140
+ class Occurence < Struct.new(:file, :line_number, :type, :language, :metadata, :result_index)
141
+ def self.from_hash(hash, index)
142
+ new.tap do |occurence|
143
+ occurence.file = hash.fetch("file")
144
+ occurence.line_number = hash.fetch("line_number") { nil }
145
+ occurence.type = hash.fetch("type") { "unknown" }
146
+ occurence.language = hash.fetch("language")
147
+ occurence.metadata = hash.fetch("metadata") { Hash.new }
148
+ occurence.result_index = index
149
+ end
150
+ end
151
+ end
152
+
153
+ class EntryOccurence < SimpleDelegator
154
+ # Used when separating out occurences for the
155
+ # editors again
156
+
157
+ def string=(string)
158
+ @string = string
159
+ end
160
+
161
+ def string
162
+ @string
163
+ end
164
+
165
+ def identifier=(identifier)
166
+ @identifier = identifier
167
+ end
168
+
169
+ def identifier
170
+ @identifier
171
+ end
172
+
173
+ def formatted_string
174
+ if language == :swift
175
+ VariableNormalizer.run(string, swift: true)
176
+ else
177
+ VariableNormalizer.run(string)
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,20 @@
1
+ module Terrestrial
2
+ module Cli
3
+ class Command
4
+
5
+ def initialize(opts)
6
+ @opts = opts
7
+ end
8
+
9
+ def self.run(opts = {})
10
+ self.new(opts).run
11
+ end
12
+
13
+ private
14
+
15
+ def opts
16
+ @opts
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module Terrestrial
2
+ module Cli
3
+ class DetectsProjectType
4
+
5
+ def self.run
6
+ files = Dir[Config[:directory] + "/**/*"]
7
+
8
+ if files.any? {|f| f.end_with?(".xcodeproj") || f.end_with?(".xcworkspace")}
9
+ "ios"
10
+ else
11
+ "android"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ module Terrestrial
2
+ module Cli
3
+ class DotStringsFormatter
4
+
5
+ def initialize(entries)
6
+ @entries = entries
7
+ end
8
+
9
+ def format_foreign_translation
10
+ result = []
11
+ entries.each do |entry|
12
+ # Just ID and string needed for translation
13
+ # files. Extra metadata is found in Base.lproj.
14
+ result << "\"#{entry.identifier}\"=\"#{entry.string}\";"
15
+ result << ""
16
+ end
17
+ result.join("\n")
18
+ end
19
+
20
+ def format
21
+ result = []
22
+ entries.each do |entry|
23
+ result.concat(file_comments(entry))
24
+ result.concat(id_and_string(entry))
25
+ result.concat(spacing)
26
+ end
27
+ result.join("\n")
28
+ end
29
+
30
+ private
31
+
32
+ def file_comments(entry)
33
+ ["// Files:"] +
34
+ entry
35
+ .occurences
36
+ .uniq {|occ| occ.file }
37
+ .map {|occ| "// - #{occ.file}" }
38
+ end
39
+
40
+ def id_and_string(entry)
41
+ ["\"#{entry.identifier}\"=\"#{entry.formatted_string}\";"]
42
+ end
43
+
44
+ def spacing
45
+ [""] # No need to put new line because of join above
46
+ end
47
+
48
+ def entries
49
+ @entries
50
+ end
51
+ end
52
+ end
53
+ end