angular_gettext 0.1.0
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.
- checksums.yaml +7 -0
- data/angular_gettext.rb +111 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 473151136c8383ee28de60e22bc0df5ce253ff37
|
4
|
+
data.tar.gz: 010dd1988993b35645f3ac05b6dcfe9b6bfeee87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65043fefe6597978bd2d02686328ada9c191c588aecda73164b2b5ba8edc418f11df0c9b379dcac3d44f142cf63576c7055eac66d784d64d76d2d94a1e4c2125
|
7
|
+
data.tar.gz: 451bc9d0bf87ab34516e02775e416cda5be62dd7c14809c6eaada60c91e6a460f1c83d006bd0819ab145ea6001b282290acc8bb73b7e4b8630f82ff2586d08e3
|
data/angular_gettext.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'Twine'
|
4
|
+
|
5
|
+
module Twine
|
6
|
+
module Formatters
|
7
|
+
class AngularGettext < Abstract
|
8
|
+
def format_name
|
9
|
+
'angular-gettext'
|
10
|
+
end
|
11
|
+
|
12
|
+
def extension
|
13
|
+
'.po'
|
14
|
+
end
|
15
|
+
|
16
|
+
def can_handle_directory?(path)
|
17
|
+
Dir.entries(path).any? { |item| /^.+\.po$/.match(item) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_file_name
|
21
|
+
return 'strings.po'
|
22
|
+
end
|
23
|
+
|
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
|
32
|
+
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
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
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def format_file(lang)
|
69
|
+
@default_lang = twine_file.language_codes[0]
|
70
|
+
result = super
|
71
|
+
@default_lang = nil
|
72
|
+
result
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_header(lang)
|
76
|
+
"msgid \"\"\nmsgstr \"\"\n\"Language: #{lang}\\n\"\n\"X-Generator: Twine #{Twine::VERSION}\\n\"\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
def format_section_header(section)
|
80
|
+
"# SECTION: #{section.name}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def should_include_definition(definition, lang)
|
84
|
+
super and !definition.translation_for_lang(@default_lang).nil?
|
85
|
+
end
|
86
|
+
|
87
|
+
def format_comment(definition, lang)
|
88
|
+
"#. \"#{escape_quotes(definition.comment)}\"\n" if definition.comment
|
89
|
+
end
|
90
|
+
|
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
|
95
|
+
|
96
|
+
def format_key(key)
|
97
|
+
"msgctxt \"#{key}\"\n"
|
98
|
+
end
|
99
|
+
|
100
|
+
def format_base_translation(definition)
|
101
|
+
"msgid \"#{definition.translations[@default_lang]}\"\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
def format_value(value)
|
105
|
+
"msgstr \"#{value}\"\n"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Twine::Formatters.formatters << Twine::Formatters::AngularGettext.new
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angular_gettext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ali BARIN
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A twine formatter for angular gettext's .POs
|
14
|
+
email: ali.barin53@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- angular_gettext.rb
|
20
|
+
homepage: http://rubygems.org/gems/angular_gettext
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Angular Gettext
|
44
|
+
test_files: []
|