angular_gettext 0.1.0 → 0.1.1

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