angular_gettext 0.1.1 → 0.1.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/angular_gettext.rb +81 -79
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4e5235555613328cec5209e1a6cbb5e03db07e9
4
- data.tar.gz: de4e1e498d5d6c4e9d5e2fc8aa9f7c57598d0bf3
3
+ metadata.gz: 17cbceac74eb3a91401e5d1cd6619d187128217f
4
+ data.tar.gz: 948f3cb28bc86d8b061483a207f21d60675b61d8
5
5
  SHA512:
6
- metadata.gz: f2b14f6eb60c7bac623afc61b7b7d3b10df3bdff10fdbf61e15f99b2ad7c99e71861c0886618cc061191df22d98fed6c5c66178c3d4ad6ed16d38cd82d9e2921
7
- data.tar.gz: aec31b6a203924e6fbd9378ea5cae1301109a9c8c28720595a293c4424c22b7afec2b7c3ec629cf6f72f16d3be71f9ace19b23b5587d9ae4001cb4cade4c64b6
6
+ metadata.gz: fe8571bf2a50cb9f4ea89a3f553401c55a5d8eed2e9a054cd4bad6c391e40ecd8235ef051b3c2ee4b3324ba3947df296f2da1cc8f9421b1e65dda12d7cf4739d
7
+ data.tar.gz: efd3b4bef9747905ca902e4ac61ac5a6a7b35bebd7887d4e38ff30caebd42a51050741a6c0367f93ee47e4eb17798db84b94ebe7024f13d14391832a54009e34
data/angular_gettext.rb CHANGED
@@ -1,105 +1,107 @@
1
1
  # encoding: utf-8
2
2
 
3
- class AngularGettext < Twine::Formatters::Abstract
4
- def format_name
5
- 'angular-gettext'
6
- end
3
+ module AngularGettext
4
+ class Formatter < Twine::Formatters::Abstract
5
+ def format_name
6
+ 'angular-gettext'
7
+ end
7
8
 
8
- def extension
9
- '.po'
10
- end
9
+ def extension
10
+ '.po'
11
+ end
11
12
 
12
- def can_handle_directory?(path)
13
- Dir.entries(path).any? { |item| /^.+\.po$/.match(item) }
14
- end
13
+ def can_handle_directory?(path)
14
+ Dir.entries(path).any? { |item| /^.+\.po$/.match(item) }
15
+ end
15
16
 
16
- def default_file_name
17
- return 'strings.po'
18
- end
17
+ def default_file_name
18
+ return 'strings.po'
19
+ end
19
20
 
20
- def determine_language_given_path(path)
21
- path_arr = path.split(File::SEPARATOR)
22
- path_arr.each do |segment|
23
- match = /(..)\.po$/.match(segment)
24
- if match
25
- return match[1]
21
+ def determine_language_given_path(path)
22
+ path_arr = path.split(File::SEPARATOR)
23
+ path_arr.each do |segment|
24
+ match = /(..)\.po$/.match(segment)
25
+ if match
26
+ return match[1]
27
+ end
26
28
  end
27
- end
28
29
 
29
- return
30
- end
30
+ return
31
+ end
31
32
 
32
- def read(io, lang)
33
- comment_regex = /#.? *"(.*)"$/
34
- key_regex = /msgctxt *"(.*)"$/
35
- value_regex = /msgstr *"(.*)"$/m
33
+ def read(io, lang)
34
+ comment_regex = /#.? *"(.*)"$/
35
+ key_regex = /msgctxt *"(.*)"$/
36
+ value_regex = /msgstr *"(.*)"$/m
36
37
 
37
- while item = io.gets("\n\n")
38
- key = nil
39
- value = nil
40
- comment = nil
38
+ while item = io.gets("\n\n")
39
+ key = nil
40
+ value = nil
41
+ comment = nil
41
42
 
42
- comment_match = comment_regex.match(item)
43
- if comment_match
44
- comment = comment_match[1]
45
- end
46
- key_match = key_regex.match(item)
47
- if key_match
48
- key = key_match[1].gsub('\\"', '"')
49
- end
50
- value_match = value_regex.match(item)
51
- if value_match
52
- value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
53
- end
54
- if key and key.length > 0 and value and value.length > 0
55
- set_translation_for_key(key, lang, value)
56
- if comment and comment.length > 0 and !comment.start_with?("SECTION:")
57
- set_comment_for_key(key, comment)
43
+ comment_match = comment_regex.match(item)
44
+ if comment_match
45
+ comment = comment_match[1]
46
+ end
47
+ key_match = key_regex.match(item)
48
+ if key_match
49
+ key = key_match[1].gsub('\\"', '"')
50
+ end
51
+ value_match = value_regex.match(item)
52
+ if value_match
53
+ value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
54
+ end
55
+ if key and key.length > 0 and value and value.length > 0
56
+ set_translation_for_key(key, lang, value)
57
+ if comment and comment.length > 0 and !comment.start_with?("SECTION:")
58
+ set_comment_for_key(key, comment)
59
+ end
60
+ comment = nil
58
61
  end
59
- comment = nil
60
62
  end
61
63
  end
62
- end
63
64
 
64
- def format_file(lang)
65
- @default_lang = twine_file.language_codes[0]
66
- result = super
67
- @default_lang = nil
68
- result
69
- end
65
+ def format_file(lang)
66
+ @default_lang = twine_file.language_codes[0]
67
+ result = super
68
+ @default_lang = nil
69
+ result
70
+ end
70
71
 
71
- def format_header(lang)
72
- "msgid \"\"\nmsgstr \"\"\n\"Language: #{lang}\\n\"\n\"X-Generator: Twine #{Twine::VERSION}\\n\"\n"
73
- end
72
+ def format_header(lang)
73
+ "msgid \"\"\nmsgstr \"\"\n\"Language: #{lang}\\n\"\n\"X-Generator: Twine #{Twine::VERSION}\\n\"\n"
74
+ end
74
75
 
75
- def format_section_header(section)
76
- "# SECTION: #{section.name}"
77
- end
76
+ def format_section_header(section)
77
+ "# SECTION: #{section.name}"
78
+ end
78
79
 
79
- def should_include_definition(definition, lang)
80
- super and !definition.translation_for_lang(@default_lang).nil?
81
- end
80
+ def should_include_definition(definition, lang)
81
+ super and !definition.translation_for_lang(@default_lang).nil?
82
+ end
82
83
 
83
- def format_comment(definition, lang)
84
- "#. \"#{escape_quotes(definition.comment)}\"\n" if definition.comment
85
- end
84
+ def format_comment(definition, lang)
85
+ "#. \"#{escape_quotes(definition.comment)}\"\n" if definition.comment
86
+ end
86
87
 
87
- def format_key_value(definition, lang)
88
- value = definition.translation_for_lang(lang)
89
- [format_key(definition.key.dup), format_base_translation(definition), format_value(value.dup)].compact.join
90
- end
88
+ def format_key_value(definition, lang)
89
+ value = definition.translation_for_lang(lang)
90
+ [format_key(definition.key.dup), format_base_translation(definition), format_value(value.dup)].compact.join
91
+ end
91
92
 
92
- def format_key(key)
93
- "msgctxt \"#{key}\"\n"
94
- end
93
+ def format_key(key)
94
+ "msgctxt \"#{key}\"\n"
95
+ end
95
96
 
96
- def format_base_translation(definition)
97
- "msgid \"#{definition.translations[@default_lang]}\"\n"
98
- end
97
+ def format_base_translation(definition)
98
+ "msgid \"#{definition.translations[@default_lang]}\"\n"
99
+ end
99
100
 
100
- def format_value(value)
101
- "msgstr \"#{value}\"\n"
101
+ def format_value(value)
102
+ "msgstr \"#{value}\"\n"
103
+ end
102
104
  end
103
105
  end
104
106
 
105
- Twine::Formatters.formatters << AngularGettext.new
107
+ Twine::Formatters.formatters << AngularGettext::Formatter.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali BARIN