tcl-msgcat 0.5 → 1.0

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: 1d08c896d423e775ef1b282c5399bd57087c3ef7
4
- data.tar.gz: c66f9414471f9a514af85e9ea1cf7f6eadf36204
3
+ metadata.gz: be4b96c3cc4b7b3dc399e0c66882623e888ee087
4
+ data.tar.gz: 317497d8d0e58a1d2755e187e2179abd31c8cb3d
5
5
  SHA512:
6
- metadata.gz: e290d35a7c371da396f1a6705b7d464fddecaab9ee44748415f9d0a7569781ed3b8128995f678acb7214e291c92c90145b3a2dc3ee3e40308e5541d94ff934bf
7
- data.tar.gz: b93c2286e49c180b27d5635918b993cecc804f48a357bfa400fa961dbf80a657fc5527b0ef043285648b9427d3b9e277864b985ad741869b80bbe5ab9f67082a
6
+ metadata.gz: b330d8ae54aa23d480fcf744d936574b04ccb50db2665c671c29421fe3fbecd630ca691195f24641a3df93f65efb05628be64b83bb4aed7b1ce44e7e31ab992f
7
+ data.tar.gz: 9447c6c2834895c966199dd6b76a0af0ae2710e27a03423df7ea8a275eede53ff465248d284b21cef795b9cb2dcedb073714fa6956551b56130f1356a026fe94
data/README.md CHANGED
@@ -32,26 +32,26 @@ Or install it yourself as:
32
32
 
33
33
  You'll want to convert your existing files first. You can do this with the following command:
34
34
 
35
- msgcat parse root.msg > root.json
36
- msgcat parse zh_tw.msg > zh_tw.json
35
+ tcl-msgcat parse root.msg > root.json
36
+ tcl-msgcat parse zh_tw.msg > zh_tw.json
37
37
 
38
38
  And render it back to the msgcat file:
39
39
 
40
- msgcat render root.json > root.test.msg
40
+ tcl-msgcat render root.json > root.test.msg
41
41
 
42
42
  OK, now say you have added a bunch of strings to your `root.json` for some new stuff in the application. You
43
43
  will want to update all your other files with those strings, and send them off to your translators. For this
44
44
  there is the `merge` action with a few ways to use it:
45
45
 
46
- msgcat merge root.json fr.json de.json es.json # specify files individually
47
- msgcat merge root.json *.json # or glob them (root.json is automatically excluded)
46
+ tcl-msgcat merge root.json fr.json de.json es.json # specify files individually
47
+ tcl-msgcat merge root.json *.json # or glob them (root.json is automatically excluded)
48
48
 
49
49
  Now you have got your files back from the translators, put them through a [linter](http://jsonlint.com/)
50
50
  and found no errors. You are ready to put those new translations back into your application. Use the `compile`
51
51
  action to run the render command on all your json files:
52
52
 
53
- msgcat compile ui/msgs # only one arg needed if you don't segregate source/compiled
54
- msgcat compile ui/msgs/source ui/msgs # otherwise specify the source and compile paths seperately
53
+ tcl-msgcat compile ui/msgs # only one arg needed if you don't segregate source/compiled
54
+ tcl-msgcat compile ui/msgs/source ui/msgs # otherwise specify the source and compile paths seperately
55
55
 
56
56
  ## Contributing
57
57
 
data/bin/tcl-msgcat ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tcl/msgcat'
4
+
5
+ case ARGV[0]
6
+ when "parse", "p"
7
+ file = ARGV[1]
8
+ puts Tcl::Msgcat.parse(file).to_json
9
+ when "uglify", "u"
10
+ file = ARGV[1]
11
+ puts Tcl::Msgcat.parse(file).to_json(false)
12
+ when "render", "r"
13
+ file = ARGV[1]
14
+ puts Tcl::Msgcat.render(file).to_s
15
+ when "merge", "m"
16
+ root = ARGV[1]
17
+ files = ARGV[2..-1]
18
+ Tcl::Msgcat.merge(root, files)
19
+ when "compile"
20
+ source_path = ARGV[1]
21
+ target_path = ARGV[2] || ARGV[1]
22
+
23
+ Tcl::Msgcat.compile(source_path, target_path)
24
+ else
25
+ puts <<-EOH
26
+ Usage: msgcat <action> <arguments>
27
+
28
+ Actions:
29
+ p|parse <file> Parse a msgcat file and output JSON
30
+ u|uglify <file> Parse a msgcat file and output ugly JSON
31
+ r|render <file> Parse a JSON file and output msgcat
32
+ m|merge <root> <files> Merge new keys from root into the files (glob pattern)
33
+ c|compile <source> [target] Compile from the source into the target
34
+
35
+ Examples:
36
+ tcl-msgcat parse ROOT.msg > root.json
37
+ tcl-msgcat uglify ROOT.msg > root.json
38
+ tcl-msgcat render root.json > ROOT.msg
39
+ tcl-msgcat merge root.json path/to/translations/*.json
40
+ tcl-msgcat merge root.json zh_tw.json fr.json de.json
41
+ tcl-msgcat compile path/to/my/json/files path/to/my/msgcat/files
42
+ tcl-msgcat compile path/to/my/json/msgcat/files
43
+ EOH
44
+ end
@@ -11,6 +11,10 @@ module Tcl
11
11
  @msgs = catalog.msgs.merge(@msgs, &merger)
12
12
  end
13
13
 
14
+ def to_json(pretty=true)
15
+ @msgs.to_json
16
+ end
17
+
14
18
  def self.load(file)
15
19
  msgs = JSON.parse(File.read(file))
16
20
  Tcl::Msgcat::Catalog.new(msgs)
@@ -1,5 +1,5 @@
1
1
  module Tcl
2
2
  module Msgcat
3
- VERSION = "0.5"
3
+ VERSION = "1.0"
4
4
  end
5
5
  end
data/lib/tcl/msgcat.rb CHANGED
@@ -6,45 +6,47 @@ require "tcl/msgcat/renderer"
6
6
 
7
7
  module Tcl
8
8
  module Msgcat
9
- def parse(msgcat_file)
10
- Tcl::Msgcat::Parser.new(msgcat_file).parse
11
- end
12
-
13
- def render(json_file)
14
- raise ArgumentError, "File not found: #{json_file}" unless File.exist? json_file
15
- msgs = JSON.parse(File.read(json_file))
16
- Tcl::Msgcat::Renderer.new(msgs).render
17
- end
9
+ class << self
10
+ def parse(msgcat_file)
11
+ Tcl::Msgcat::Parser.new(msgcat_file).parse
12
+ end
18
13
 
19
- def merge(root_file, translation_files=[])
20
- if translation_files.is_a? String
21
- translation_files = Dir[translation_files]
14
+ def render(json_file)
15
+ raise ArgumentError, "File not found: #{json_file}" unless File.exist? json_file
16
+ msgs = JSON.parse(File.read(json_file))
17
+ Tcl::Msgcat::Renderer.new(msgs).render
22
18
  end
23
19
 
24
- root = Tcl::Msgcat::Catalog.load(root_file)
20
+ def merge(root_file, translation_files=[])
21
+ if translation_files.is_a? String
22
+ translation_files = Dir[translation_files]
23
+ end
24
+
25
+ root = Tcl::Msgcat::Catalog.load(root_file)
25
26
 
26
- translation_files.each do |file|
27
- next if File.basename(file) == File.basename(root_file)
28
- print "Merging new translations into #{file}... "
29
- catalog = Tcl::Msgcat::Catalog.load(file)
30
- catalog.merge!(root)
31
- File.open(file, "w") {|f| f.write catalog.to_json }
32
- puts "done"
27
+ translation_files.each do |file|
28
+ next if File.basename(file) == File.basename(root_file)
29
+ print "Merging new translations into #{file}... "
30
+ catalog = Tcl::Msgcat::Catalog.load(file)
31
+ catalog.merge!(root)
32
+ File.open(file, "w") {|f| f.write catalog.to_json }
33
+ puts "done"
34
+ end
33
35
  end
34
- end
35
36
 
36
- def compile(source, target)
37
- raise ArgumentError, "Not a directory: #{source}" unless File.directory? source
38
- raise ArgumentError, "Not a directory: #{target}" unless File.directory? target
37
+ def compile(source, target)
38
+ raise ArgumentError, "Not a directory: #{source}" unless File.directory? source
39
+ raise ArgumentError, "Not a directory: #{target}" unless File.directory? target
39
40
 
40
- Dir["#{source}/*.json"].each do |src|
41
- dst = File.basename(src, ".json")+".msg"
42
- print "Compiling #{src} to #{target}/#{dst}... "
43
- msgs = JSON.parse(File.read(src))
44
- renderer = Tcl::Msgcat::Renderer.new(msgs).render
45
- File.write("#{target}/#{dst}") {|f| f.write renderer.to_s }
46
- puts "done"
41
+ Dir["#{source}/*.json"].each do |src|
42
+ dst = File.basename(src, ".json")+".msg"
43
+ print "Compiling #{src} to #{target}/#{dst}... "
44
+ msgs = JSON.parse(File.read(src))
45
+ renderer = Tcl::Msgcat::Renderer.new(msgs).render
46
+ File.write("#{target}/#{dst}") {|f| f.write renderer.to_s }
47
+ puts "done"
48
+ end
47
49
  end
48
50
  end
49
51
  end
50
- end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcl-msgcat
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '1.0'
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-22 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,7 +42,7 @@ description: Library for parsing, rendering and merging TCL msgcat files
42
42
  email:
43
43
  - robert@autogrow.com
44
44
  executables:
45
- - msgcat
45
+ - tcl-msgcat
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
@@ -51,7 +51,7 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
- - bin/msgcat
54
+ - bin/tcl-msgcat
55
55
  - lib/tcl/msgcat.rb
56
56
  - lib/tcl/msgcat/catalog.rb
57
57
  - lib/tcl/msgcat/parser.rb
data/bin/msgcat DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'tcl-msgcat'
4
-
5
- case ARGV[0]
6
- when "parse", "p"
7
- file = ARGV[1]
8
- puts Tcl::Msgcat.parse(file).to_json
9
- when "render", "r"
10
- file = ARGV[1]
11
- puts Tcl::Msgcat.render(file).to_s
12
- when "merge", "m"
13
- root = ARGV[1]
14
- files = ARGV[2..-1]
15
- Tcl::Msgcat.merge(root, files)
16
- when "compile"
17
- source_path = ARGV[1]
18
- target_path = ARGV[2] || ARGV[1]
19
-
20
- Tcl::Msgcat.compile(source_path, target_path)
21
- else
22
- puts <<-EOH
23
- Usage: msgcat <action> <arguments>
24
-
25
- Actions:
26
- parse <file> Parse a msgcat file and output JSON
27
- render <file> Parse a JSON file and output msgcat
28
- merge <root> <files> Merge new keys from root into the files (glob pattern)
29
- compile <source> [target] Compile from the source into the target
30
-
31
- Examples:
32
- msgcat parse ROOT.msg > root.json
33
- msgcat render root.json > ROOT.msg
34
- msgcat merge root.json path/to/translations/*.json
35
- msgcat merge root.json zh_tw.json fr.json de.json
36
- msgcat compile path/to/my/json/files path/to/my/msgcat/files
37
- msgcat compile path/to/my/json/msgcat/files
38
- EOH
39
- end