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

github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/twine/formatters')
-rw-r--r--lib/twine/formatters/abstract.rb84
-rw-r--r--lib/twine/formatters/android.rb10
-rw-r--r--lib/twine/formatters/apple.rb4
-rw-r--r--lib/twine/formatters/django.rb14
-rw-r--r--lib/twine/formatters/flash.rb6
-rw-r--r--lib/twine/formatters/gettext.rb20
-rw-r--r--lib/twine/formatters/jquery.rb12
-rw-r--r--lib/twine/formatters/tizen.rb6
8 files changed, 78 insertions, 78 deletions
diff --git a/lib/twine/formatters/abstract.rb b/lib/twine/formatters/abstract.rb
index 012346e..c337a60 100644
--- a/lib/twine/formatters/abstract.rb
+++ b/lib/twine/formatters/abstract.rb
@@ -3,11 +3,11 @@ require 'fileutils'
module Twine
module Formatters
class Abstract
- attr_accessor :strings
+ attr_accessor :twine_file
attr_accessor :options
def initialize
- @strings = StringsFile.new
+ @twine_file = TwineFile.new
@options = {}
end
@@ -30,47 +30,47 @@ module Twine
def set_translation_for_key(key, lang, value)
value = value.gsub("\n", "\\n")
- if @strings.strings_map.include?(key)
- row = @strings.strings_map[key]
- reference = @strings.strings_map[row.reference_key] if row.reference_key
+ 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]
- row.translations[lang] = value
+ definition.translations[lang] = value
end
elsif @options[:consume_all]
- Twine::stderr.puts "Adding new string '#{key}' to strings data file."
- current_section = @strings.sections.find { |s| s.name == 'Uncategorized' }
+ 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 = StringsSection.new('Uncategorized')
- @strings.sections.insert(0, current_section)
+ current_section = TwineSection.new('Uncategorized')
+ @twine_file.sections.insert(0, current_section)
end
- current_row = StringsRow.new(key)
- current_section.rows << current_row
+ current_definition = TwineDefinition.new(key)
+ current_section.definitions << current_definition
if @options[:tags] && @options[:tags].length > 0
- current_row.tags = @options[:tags]
+ current_definition.tags = @options[:tags]
end
- @strings.strings_map[key] = current_row
- @strings.strings_map[key].translations[lang] = value
+ @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 strings data file."
+ Twine::stderr.puts "Warning: '#{key}' not found in twine file."
end
- if !@strings.language_codes.include?(lang)
- @strings.add_language_code(lang)
+ 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 @strings.strings_map.include?(key)
- row = @strings.strings_map[key]
+ if @twine_file.definitions_by_key.include?(key)
+ definition = @twine_file.definitions_by_key[key]
- reference = @strings.strings_map[row.reference_key] if row.reference_key
+ reference = @twine_file.definitions_by_key[definition.reference_key] if definition.reference_key
if !reference or comment != reference.raw_comment
- row.comment = comment
+ definition.comment = comment
end
end
end
@@ -88,35 +88,35 @@ module Twine
end
def format_file(lang)
- output_processor = Processors::OutputProcessor.new(@strings, @options)
- processed_strings = output_processor.process(lang)
+ output_processor = Processors::OutputProcessor.new(@twine_file, @options)
+ processed_twine_file = output_processor.process(lang)
- return nil if processed_strings.strings_map.empty?
+ return nil if processed_twine_file.definitions_by_key.empty?
header = format_header(lang)
result = ""
result += header + "\n" if header
- result += format_sections(processed_strings, lang)
+ result += format_sections(processed_twine_file, lang)
end
def format_header(lang)
end
- def format_sections(strings, lang)
- sections = strings.sections.map { |section| format_section(section, lang) }
+ 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_row(row, lang)
- row.translated_string_for_lang(lang)
+ def should_include_definition(definition, lang)
+ return !definition.translation_for_lang(lang).nil?
end
def format_section(section, lang)
- rows = section.rows.select { |row| should_include_row(row, lang) }
- return if rows.empty?
+ definitions = section.definitions.select { |definition| should_include_definition(definition, lang) }
+ return if definitions.empty?
result = ""
@@ -125,22 +125,22 @@ module Twine
result += "\n#{section_header}" if section_header
end
- rows.map! { |row| format_row(row, lang) }
- rows.compact! # remove nil entries
- rows.map! { |row| "\n#{row}" } # prepend newline
- result += rows.join
+ 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_row(row, lang)
- [format_comment(row, lang), format_key_value(row, lang)].compact.join
+ def format_definition(definition, lang)
+ [format_comment(definition, lang), format_key_value(definition, lang)].compact.join
end
- def format_comment(row, lang)
+ def format_comment(definition, lang)
end
- def format_key_value(row, lang)
- value = row.translated_string_for_lang(lang)
- key_value_pattern % { key: format_key(row.key.dup), value: format_value(value.dup) }
+ 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
diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb
index 448826d..caddec8 100644
--- a/lib/twine/formatters/android.rb
+++ b/lib/twine/formatters/android.rb
@@ -37,7 +37,7 @@ module Twine
path_arr = path.split(File::SEPARATOR)
path_arr.each do |segment|
if segment == 'values'
- return @strings.language_codes[0]
+ 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
@@ -105,7 +105,7 @@ module Twine
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Android Strings File -->\n<!-- Generated by Twine #{Twine::VERSION} -->\n<!-- Language: #{lang} -->"
end
- def format_sections(strings, lang)
+ def format_sections(twine_file, lang)
result = '<resources>'
result += super + "\n"
@@ -117,8 +117,8 @@ module Twine
"\t<!-- SECTION: #{section.name} -->"
end
- def format_comment(row, lang)
- "\t<!-- #{row.comment.gsub('--', '—')} -->\n" if row.comment
+ def format_comment(definition, lang)
+ "\t<!-- #{definition.comment.gsub('--', '—')} -->\n" if definition.comment
end
def key_value_pattern
@@ -137,7 +137,7 @@ module Twine
# 4) 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, '\@')
- # 5) replace beginning and end spaces with \0020. Otherwise Android strips them.
+ # 5) replace beginning and end spaces with \u0020. Otherwise Android strips them.
value.gsub(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
end
diff --git a/lib/twine/formatters/apple.rb b/lib/twine/formatters/apple.rb
index 9546e2b..056ada7 100644
--- a/lib/twine/formatters/apple.rb
+++ b/lib/twine/formatters/apple.rb
@@ -73,8 +73,8 @@ module Twine
"\"%{key}\" = \"%{value}\";\n"
end
- def format_comment(row, lang)
- "/* #{row.comment.gsub('*/', '* /')} */\n" if row.comment
+ def format_comment(definition, lang)
+ "/* #{definition.comment.gsub('*/', '* /')} */\n" if definition.comment
end
def format_key(key)
diff --git a/lib/twine/formatters/django.rb b/lib/twine/formatters/django.rb
index b63657e..dd60c4f 100644
--- a/lib/twine/formatters/django.rb
+++ b/lib/twine/formatters/django.rb
@@ -63,7 +63,7 @@ module Twine
end
def format_file(lang)
- @default_lang = @strings.language_codes[0]
+ @default_lang = @twine_file.language_codes[0]
result = super
@default_lang = nil
result
@@ -77,12 +77,12 @@ module Twine
"#--------- #{section.name} ---------#\n"
end
- def format_row(row, lang)
- [format_comment(row, lang), format_base_translation(row), format_key_value(row, lang)].compact.join
+ 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(row)
- base_translation = row.translations[@default_lang]
+ def format_base_translation(definition)
+ base_translation = definition.translations[@default_lang]
"# base translation: \"#{base_translation}\"\n" if base_translation
end
@@ -91,8 +91,8 @@ module Twine
"msgstr \"%{value}\"\n"
end
- def format_comment(row, lang)
- "#. #{escape_quotes(row.comment)}\n" if row.comment
+ def format_comment(definition, lang)
+ "#. #{escape_quotes(definition.comment)}\n" if definition.comment
end
def format_key(key)
diff --git a/lib/twine/formatters/flash.rb b/lib/twine/formatters/flash.rb
index 8cc29da..3aaee70 100644
--- a/lib/twine/formatters/flash.rb
+++ b/lib/twine/formatters/flash.rb
@@ -44,7 +44,7 @@ module Twine
end
end
- def format_sections(strings, lang)
+ def format_sections(twine_file, lang)
super + "\n"
end
@@ -56,8 +56,8 @@ module Twine
"## #{section.name} ##\n"
end
- def format_comment(row, lang)
- "# #{row.comment}\n" if row.comment
+ def format_comment(definition, lang)
+ "# #{definition.comment}\n" if definition.comment
end
def key_value_pattern
diff --git a/lib/twine/formatters/gettext.rb b/lib/twine/formatters/gettext.rb
index 71b9a84..90553bd 100644
--- a/lib/twine/formatters/gettext.rb
+++ b/lib/twine/formatters/gettext.rb
@@ -64,7 +64,7 @@ module Twine
end
def format_file(lang)
- @default_lang = strings.language_codes[0]
+ @default_lang = twine_file.language_codes[0]
result = super
@default_lang = nil
result
@@ -78,25 +78,25 @@ module Twine
"# SECTION: #{section.name}"
end
- def should_include_row(row, lang)
- super and row.translated_string_for_lang(@default_lang)
+ def should_include_definition(definition, lang)
+ super and !definition.translation_for_lang(@default_lang).nil?
end
- def format_comment(row, lang)
- "#. \"#{escape_quotes(row.comment)}\"\n" if row.comment
+ def format_comment(definition, lang)
+ "#. \"#{escape_quotes(definition.comment)}\"\n" if definition.comment
end
- def format_key_value(row, lang)
- value = row.translated_string_for_lang(lang)
- [format_key(row.key.dup), format_base_translation(row), format_value(value.dup)].compact.join
+ 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(row)
- "msgid \"#{row.translations[@default_lang]}\"\n"
+ def format_base_translation(definition)
+ "msgid \"#{definition.translations[@default_lang]}\"\n"
end
def format_value(value)
diff --git a/lib/twine/formatters/jquery.rb b/lib/twine/formatters/jquery.rb
index 310f041..8d60116 100644
--- a/lib/twine/formatters/jquery.rb
+++ b/lib/twine/formatters/jquery.rb
@@ -48,8 +48,8 @@ module Twine
"{\n#{super}\n}\n"
end
- def format_sections(strings, lang)
- sections = strings.sections.map { |section| format_section(section, lang) }
+ def format_sections(twine_file, lang)
+ sections = twine_file.sections.map { |section| format_section(section, lang) }
sections.join(",\n\n")
end
@@ -57,11 +57,11 @@ module Twine
end
def format_section(section, lang)
- rows = section.rows.dup
+ definitions = section.definitions.dup
- rows.map! { |row| format_row(row, lang) }
- rows.compact! # remove nil entries
- rows.join(",\n")
+ definitions.map! { |definition| format_definition(definition, lang) }
+ definitions.compact! # remove nil definitions
+ definitions.join(",\n")
end
def key_value_pattern
diff --git a/lib/twine/formatters/tizen.rb b/lib/twine/formatters/tizen.rb
index 8c9fae8..21ba771 100644
--- a/lib/twine/formatters/tizen.rb
+++ b/lib/twine/formatters/tizen.rb
@@ -94,7 +94,7 @@ module Twine
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Tizen Strings File -->\n<!-- Generated by Twine #{Twine::VERSION} -->\n<!-- Language: #{lang} -->"
end
- def format_sections(strings, lang)
+ def format_sections(twine_file, lang)
result = '<string_table Bversion="2.0.0.201311071819" Dversion="20120315">'
result += super + "\n"
@@ -106,8 +106,8 @@ module Twine
"\t<!-- SECTION: #{section.name} -->"
end
- def format_comment(row, lang)
- "\t<!-- #{row.comment.gsub('--', '—')} -->\n" if row.comment
+ def format_comment(definition, lang)
+ "\t<!-- #{definition.comment.gsub('--', '—')} -->\n" if definition.comment
end
def key_value_pattern