babelphish 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/babelphish/translator.rb +19 -10
- data/lib/babelphish.rb +1 -1
- metadata +2 -2
@@ -3,8 +3,6 @@ require 'ya2yaml'
|
|
3
3
|
require 'babelphish/languages'
|
4
4
|
require 'jcode'
|
5
5
|
|
6
|
-
require 'ruby-debug'
|
7
|
-
|
8
6
|
module Babelphish
|
9
7
|
module Translator
|
10
8
|
class << self
|
@@ -28,6 +26,9 @@ module Babelphish
|
|
28
26
|
return if File.exist?(translated_filename) && !overwrite
|
29
27
|
translated_yml = YAML.load_file(yml)
|
30
28
|
translate_keys(translated_yml, to, from)
|
29
|
+
# change the top level key from the source language to the destination language
|
30
|
+
translated_yml[to] = translated_yml[from]
|
31
|
+
translated_yml.delete(from)
|
31
32
|
File.open(translated_filename, 'w') { |f| f.write(translated_yml.ya2yaml) }
|
32
33
|
end
|
33
34
|
|
@@ -36,14 +37,22 @@ module Babelphish
|
|
36
37
|
if translate_hash[key].is_a?(Hash)
|
37
38
|
translate_keys(translate_hash[key], to, from)
|
38
39
|
else
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
translate_hash[key]
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
if key == false
|
41
|
+
puts "Key #{key} was evaluated as false. Check your yml file and be sure to escape values like no with 'no'. ie 'no': 'No'"
|
42
|
+
elsif key == true
|
43
|
+
puts "Key #{key} was evaluated as true. Check your yml file and be sure to escape values like yes with 'yes'. ie 'yes': 'Yes'"
|
44
|
+
elsif translate_hash[key]
|
45
|
+
# pull out all the string substitutions so that google doesn't translate those
|
46
|
+
pattern = /\{\{.+\}\}/
|
47
|
+
holder = '{{---}}'
|
48
|
+
replacements = translate_hash[key].scan(pattern)
|
49
|
+
translate_hash[key].gsub!(pattern, holder)
|
50
|
+
translate_hash[key] = translate(translate_hash[key], to, from)
|
51
|
+
replacements.each do |r|
|
52
|
+
translate_hash[key].sub!(holder, r)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "Key #{key} contains no data"
|
47
56
|
end
|
48
57
|
end
|
49
58
|
end
|
data/lib/babelphish.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babelphish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-18 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|