tcl-msgcat 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ff7447fc76a7ccb6dea7788a0a3aacf27ed2870
4
- data.tar.gz: a4af1f28cce43b76238c5e5cf100bab394e7da78
3
+ metadata.gz: 89c47db074b3409ff9c670defdb7a9b256294b61
4
+ data.tar.gz: 5b5d217ddcf76f716a5cdeb9879ba4d3e583ce99
5
5
  SHA512:
6
- metadata.gz: 4842aa60208f3879df71e0eced768922d73c4c56b8251069f103a963fd69302062958ab3b546d21114aaffffad768754d50e6b5b42f13e1cea8575617ba1873b
7
- data.tar.gz: dfc920dd5da1beb4dadf8a16d424567c55940dadcc4a83ccdf04ebc9e74bc76b6650198b9f3712861a598f40b87e8b9f86ab041ec04dd5674b4cfa6a47f3ab91
6
+ metadata.gz: 3c9a407328c7a8ec11b9ee6066ebfa42759b07b13efa1238139a86fdfbceae3f651590a1e4dc72ad396baf9d4052bf9bf05276c212077ebb5fffb4dd79a27f0f
7
+ data.tar.gz: e0687bb8c40892a2a3b77169fb62f3f91e0ca7c8ced48aefa52c9eac097a64eb9d610c1413b5c841af77a66f6edc7279b2ec87e808852d9dbb7a6a6dc14bf72c
data/bin/tcl-msgcat CHANGED
@@ -11,7 +11,11 @@ when "uglify", "u"
11
11
  puts Tcl::Msgcat.parse(file).to_json(false)
12
12
  when "render", "r"
13
13
  file = ARGV[1]
14
- puts Tcl::Msgcat.render(file).to_s
14
+ begin
15
+ puts Tcl::Msgcat.render(file).to_s
16
+ rescue MultiJson::ParseError => e
17
+ abort "ERROR: Invalid JSON: #{e.message}"
18
+ end
15
19
  when "merge", "m"
16
20
  root = ARGV[1]
17
21
  files = ARGV[2..-1]
data/lib/tcl/msgcat.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'json'
2
+ require 'oj'
3
+ require 'multi_json'
2
4
  require "tcl/msgcat/version"
3
5
  require "tcl/msgcat/catalog"
4
6
  require "tcl/msgcat/parser"
@@ -18,8 +20,9 @@ module Tcl
18
20
 
19
21
  def render(json_file)
20
22
  raise ArgumentError, "File not found: #{json_file}" unless File.exist? json_file
21
- msgs = JSON.parse(File.read(json_file))
22
- Tcl::Msgcat::Renderer.new(msgs).render
23
+ msgs = MultiJson.load(File.read(json_file))
24
+ lang = File.basename(json_file, File.extname(json_file))
25
+ Tcl::Msgcat::Renderer.new(msgs, lang).render
23
26
  end
24
27
 
25
28
  def merge(root_file, translation_files=[])
@@ -27,15 +30,23 @@ module Tcl
27
30
  translation_files = Dir[translation_files]
28
31
  end
29
32
 
30
- root = Tcl::Msgcat::Catalog.load(root_file)
33
+ begin
34
+ root = Tcl::Msgcat::Catalog.load(root_file)
35
+ rescue MultiJson::ParseError => e
36
+ raise MultiJson::ParseError, "Failed to parse #{root_file}: #{e.message}"
37
+ end
31
38
 
32
39
  translation_files.each do |file|
33
- next if File.basename(file) == File.basename(root_file)
34
- print "Merging new translations into #{file}... "
35
- catalog = Tcl::Msgcat::Catalog.load(file)
36
- catalog.merge!(root)
37
- File.open(file, "w") {|f| f.write catalog.to_json }
38
- puts "done"
40
+ begin
41
+ next if File.basename(file) == File.basename(root_file)
42
+ print "Merging new translations into #{file}... "
43
+ catalog = Tcl::Msgcat::Catalog.load(file)
44
+ catalog.merge!(root)
45
+ File.open(file, "w") {|f| f.write catalog.to_json }
46
+ puts "done"
47
+ rescue MultiJson::ParseError => e
48
+ raise MultiJson::ParseError, "Failed to parse #{file}: #{e.message}"
49
+ end
39
50
  end
40
51
  end
41
52
 
@@ -46,10 +57,12 @@ module Tcl
46
57
  Dir["#{source}/*.json"].each do |src|
47
58
  dst = File.basename(src, ".json")+".msg"
48
59
  print "Compiling #{src} to #{target}/#{dst}... "
49
- msgs = JSON.parse(File.read(src))
50
- renderer = Tcl::Msgcat::Renderer.new(msgs).render
51
- File.write("#{target}/#{dst}") {|f| f.write renderer.to_s }
52
- puts "done"
60
+ begin
61
+ File.write("#{target}/#{dst}") {|f| f.write render(src) }
62
+ puts "done"
63
+ rescue ArgumentError => e
64
+ puts e.message
65
+ end
53
66
  end
54
67
  end
55
68
  end
@@ -16,7 +16,7 @@ module Tcl
16
16
  end
17
17
 
18
18
  def self.load(file)
19
- msgs = JSON.parse(File.read(file))
19
+ msgs = MultiJson.load(File.read(file))
20
20
  Tcl::Msgcat::Catalog.new(msgs)
21
21
  end
22
22
  end
@@ -2,14 +2,21 @@ module Tcl
2
2
  module Msgcat
3
3
  class Renderer
4
4
  attr_reader :msgs, :lines
5
- def initialize(msgs)
5
+ def initialize(msgs, lang=nil)
6
6
  @msgs = msgs
7
+ @lang = lang
7
8
  @lines = []
8
9
  end
9
10
 
10
11
  def render
11
12
  @lines << "package require mchelper"
12
- @lines << "msg_lang {}"
13
+
14
+ if (@lang.nil? or @lang.downcase == "root")
15
+ @lines << "msg_lang {}"
16
+ else
17
+ @lines << "msg_lang #{@lang}"
18
+ end
19
+
13
20
  @lines << ""
14
21
  _render(@msgs)
15
22
 
@@ -1,5 +1,5 @@
1
1
  module Tcl
2
2
  module Msgcat
3
- VERSION = "1.0.4"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
data/tcl-msgcat.gemspec CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "multi_json"
22
+ spec.add_dependency "oj"
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.7"
22
25
  spec.add_development_dependency "rake", "~> 10.0"
23
26
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcl-msgcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert McLeod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement