diff --git a/Gemfile.lock b/Gemfile.lock index f26e8a4..e6bbbd6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - xliffle (0.0.3) + xliffle (0.0.4) builder rails (~> 4.1.4) diff --git a/README.md b/README.md index 7fa557d..4bb7666 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ xliffle = Xliffle.new ``` file = xliffle.file('de.po', 'de', 'en') -=> # +=> # ``` Parameters: @@ -35,17 +35,18 @@ Parameters: ``` file.string('admin.foo_bar','Foo', 'Bar') -=> # +=> # ``` Parameters: - +* name - identifier for the string * source string * target string ### Export to file -```xliffle.to_file +``` +xliffle.to_file => # ``` @@ -55,7 +56,7 @@ Returns temporary xliff-file ``` xliffle.to_xliff -=> "\n\n \n \n \n Foo\n Bar\n \n \n \n\n" +=> "\n\n \n \n \n Foo\n Bar\n \n \n \n\n" ``` Returns xliff structure as string diff --git a/lib/xliffle/creator.rb b/lib/xliffle/creator.rb index a88e733..fdaf3a5 100644 --- a/lib/xliffle/creator.rb +++ b/lib/xliffle/creator.rb @@ -9,7 +9,7 @@ def initialize end def file(original, source_locale, target_locale) - file = Xliffle::File.new(original, source_locale, target_locale) + file = Xliffle::File.new(file_id, original, source_locale, target_locale) @files << file file end @@ -31,6 +31,10 @@ def to_file private + def file_id + @files.length.succ + end + def xml(&block) xml = Builder::XmlMarkup.new( :indent => 2 ) xml.instruct! :xml, :encoding => "UTF-8" diff --git a/lib/xliffle/file.rb b/lib/xliffle/file.rb index f2f2b85..619a716 100644 --- a/lib/xliffle/file.rb +++ b/lib/xliffle/file.rb @@ -2,15 +2,16 @@ module Xliffle class File attr_reader :original, :strings, :source_locale, :target_locale - def initialize(original, source_locale, target_locale) + def initialize(id, original, source_locale, target_locale) + @id = id @strings = [] @original = original @source_locale = source_locale @target_locale = target_locale end - def string(id, source, target) - string = Xliffle::String.new(id, source, target) + def string(name, source, target) + string = Xliffle::String.new(string_id, name, source, target) @strings << string string end @@ -24,5 +25,11 @@ def to_xliff(xliff) end end end + + private + + def string_id + "#{ @id }_#{ @strings.length.succ }" + end end end diff --git a/lib/xliffle/string.rb b/lib/xliffle/string.rb index 37b4c12..10fe8e8 100644 --- a/lib/xliffle/string.rb +++ b/lib/xliffle/string.rb @@ -1,15 +1,16 @@ module Xliffle class String - attr_reader :id, :source, :target + attr_reader :name, :source, :target - def initialize(id, source, target) + def initialize(id, name, source, target) @id = id + @name = name @source = source @target = target end def to_xliff(xliff) - xliff.tag!('trans-unit', { id: @id }) do |t| + xliff.tag!('trans-unit', { id: @id, resname: @name }) do |t| t.source(@source) t.target(@target) end diff --git a/lib/xliffle/version.rb b/lib/xliffle/version.rb index ceef2e8..33a3f56 100644 --- a/lib/xliffle/version.rb +++ b/lib/xliffle/version.rb @@ -1,3 +1,3 @@ module Xliffle - VERSION = "0.0.3" + VERSION = "0.0.4" end