Class: Twine::Formatters::Gettext
Constant Summary
Constants inherited
from Abstract
Abstract::LANGUAGE_CODE_WITH_OPTIONAL_REGION_CODE
Instance Attribute Summary
Attributes inherited from Abstract
#options, #twine_file
Instance Method Summary
collapse
Methods inherited from Abstract
#can_handle_directory?, #determine_language_given_path, #escape_quotes, #format_definition, #format_section, #format_sections, #initialize, #key_value_pattern, #output_path_for_language, #set_comment_for_key, #set_translation_for_key
Instance Method Details
#default_file_name ⇒ Object
14
15
16
|
# File 'lib/twine/formatters/gettext.rb', line 14
def default_file_name
'strings.po'
end
|
#extension ⇒ Object
10
11
12
|
# File 'lib/twine/formatters/gettext.rb', line 10
def extension
'.po'
end
|
82
83
84
|
# File 'lib/twine/formatters/gettext.rb', line 82
def format_base_translation(definition)
"msgid \"#{escape_quotes(definition.translations[@default_lang])}\"\n"
end
|
69
70
71
|
# File 'lib/twine/formatters/gettext.rb', line 69
def (definition, lang)
"#. \"#{escape_quotes(definition.)}\"\n" if definition.
end
|
50
51
52
53
54
55
|
# File 'lib/twine/formatters/gettext.rb', line 50
def format_file(lang)
@default_lang = twine_file.language_codes[0]
result = super
@default_lang = nil
result
end
|
57
58
59
|
# File 'lib/twine/formatters/gettext.rb', line 57
def (lang)
"msgid \"\"\nmsgstr \"\"\n\"Language: #{lang}\"\n\"X-Generator: Twine #{Twine::VERSION}\"\n"
end
|
78
79
80
|
# File 'lib/twine/formatters/gettext.rb', line 78
def format_key(key)
"msgctxt \"#{escape_quotes(key)}\"\n"
end
|
73
74
75
76
|
# File 'lib/twine/formatters/gettext.rb', line 73
def format_key_value(definition, lang)
value = definition.translation_for_lang(lang)
[format_key(definition.key.dup), format_base_translation(definition), format_value(value.dup)].compact.join
end
|
6
7
8
|
# File 'lib/twine/formatters/gettext.rb', line 6
def format_name
'gettext'
end
|
61
62
63
|
# File 'lib/twine/formatters/gettext.rb', line 61
def (section)
"# SECTION: #{section.name}"
end
|
86
87
88
|
# File 'lib/twine/formatters/gettext.rb', line 86
def format_value(value)
"msgstr \"#{escape_quotes(value)}\"\n"
end
|
#read(io, lang) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/twine/formatters/gettext.rb', line 18
def read(io, lang)
= /#.? *"(.*)"$/
key_regex = /msgctxt *"(.*)"$/
value_regex = /msgstr *"(.*)"$/m
while item = io.gets("\n\n")
key = nil
value = nil
= nil
= .match(item)
if
= [1]
end
key_match = key_regex.match(item)
if key_match
key = key_match[1].gsub('\\"', '"')
end
value_match = value_regex.match(item)
if value_match
value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
end
if key and key.length > 0 and value and value.length > 0
set_translation_for_key(key, lang, value)
if and .length > 0 and !.start_with?("SECTION:")
(key, )
end
= nil
end
end
end
|
#should_include_definition(definition, lang) ⇒ Object
65
66
67
|
# File 'lib/twine/formatters/gettext.rb', line 65
def should_include_definition(definition, lang)
super and !definition.translation_for_lang(@default_lang).nil?
end
|