PoParser 3.2.0 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 69d284ad281dcb8de53d79a3b92fb1336ee5ca7a
4
- data.tar.gz: a33178e0caffc6d999b3eaf0707cc1c39aa9551f
2
+ SHA256:
3
+ metadata.gz: 392d8f812cf03d26f88eb36e87a7123cdec137c5858e516b236c02890a987c7d
4
+ data.tar.gz: 1fc9a420db5ec1074f0a214d272d8863c390fccab25c18af6c5b423967a88f38
5
5
  SHA512:
6
- metadata.gz: 7b780472d5fa52e5b21fffdd65f876c4cf7434bea99b917b6d41baa6c4ba5898b7a6d6175015dd7f098b9e381618c5b8f625d6900b15c496b8ce27bb7da2159d
7
- data.tar.gz: 4bbb2febfc6990f33c2788b6a96cdee43b1c8e394925b009a72cc477ad7b7467d88a6174c94201a56330b7dd5a7971d2dc8f681d6980d3d5275f48bf7aed767d
6
+ metadata.gz: 3c03f5ced1b5a31b785b32edc91b7a9f1979a0132e469adf7422de5124947feca04e5aaab4a32fa7b8d41663ff517db012f4a56f918f6cc37b8eb12fcd94703c
7
+ data.tar.gz: b50ec41094db0f27066a3b7482e7a0b7e307e7f9afbf54b81c07f97190f3419bc32d8c53e02767dfbaea95e75c6b8878952720ff847b566af73a928222a23ca6
@@ -0,0 +1,41 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
36
+
37
+ - name: Coveralls
38
+ uses: coverallsapp/github-action@master
39
+ with:
40
+ github-token: ${{ secrets.GITHUB_TOKEN }}
41
+ path-to-lcov: "./coverage/lcov.info"
@@ -1,13 +1,8 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.6
3
3
  Exclude:
4
4
  - 'spec/**/*'
5
- - 'db/**/*'
6
- - 'app/views/**/*'
7
- - 'config/**/*'
8
5
  - 'bin/*'
9
- - 'Rakefile'
10
- - 'node_modules/**/*'
11
6
 
12
7
  Bundler/OrderedGems:
13
8
  Enabled: false
@@ -27,9 +22,28 @@ Layout/AlignParameters:
27
22
  EnforcedStyle: with_fixed_indentation
28
23
 
29
24
  Style/FrozenStringLiteralComment:
30
- Enabled: false
25
+ Enabled: true
31
26
 
32
27
  Style/PercentLiteralDelimiters:
33
28
  PreferredDelimiters:
34
29
  '%i': '()'
35
30
  '%w': '()'
31
+
32
+ Style/TrailingCommaInArrayLiteral:
33
+ Enabled: true
34
+ EnforcedStyleForMultiline: comma
35
+
36
+ Style/TrailingCommaInHashLiteral:
37
+ Enabled: true
38
+ EnforcedStyleForMultiline: comma
39
+
40
+ Style/TrailingCommaInArguments:
41
+ Enabled: true
42
+ EnforcedStyleForMultiline: comma
43
+
44
+ Layout/EmptyLines:
45
+ Enabled: true
46
+
47
+ Metrics/LineLength:
48
+ Max: 100
49
+ IgnoreCopDirectives: True
@@ -1,3 +1,23 @@
1
+ 3.2.4 / 2019-10-12
2
+ ==================
3
+
4
+ * remove rspec binstub, Courtesy of @Fryguy
5
+
6
+ 3.2.3 / 2019-03-23
7
+ ==================
8
+
9
+ * Entries can be removed, Courtesy of @lremes
10
+ * Cleanups and refactors
11
+
12
+ 3.2.2 / 2018-05-03
13
+ ==================
14
+
15
+ * Fix warning in JRuby 9.1.14.0 Courtesy of @remofritzsche
16
+
17
+ 3.2.1 / 2017-09-05
18
+ ==================
19
+
20
+ * Update header.rb (#21) Courtesy of @mallowigi
1
21
 
2
22
  3.2.0 / 2017-06-29
3
23
  ==================
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mousavi.arash@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile CHANGED
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  group :test do
4
- gem 'coveralls', :require => false
5
- gem 'rspec', '~> 3.6.0'
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+ gem 'rspec', '~> 3.9'
6
9
  gem 'awesome_print'
7
10
  end
8
11
 
9
12
  group :development do
10
- gem 'guard-rspec'
11
13
  gem 'ruby-prof'
12
14
  end
13
15
 
14
16
  group :test, :development do
15
- gem 'pry-byebug', :platforms => :mri
17
+ gem 'pry-byebug', platforms: :mri
16
18
  end
17
19
 
18
20
  # Specify your gem's dependencies in poparser.gemspec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # PoParser
2
2
 
3
- [![Build Status](https://travis-ci.org/arashm/PoParser.svg?branch=master)](https://travis-ci.org/arashm/PoParser)
4
- [![Coverage Status](https://img.shields.io/coveralls/arashm/PoParser.svg)](https://coveralls.io/r/arashm/PoParser)
3
+ ![Build Status](https://github.com/arashm/poparser/workflows/Ruby/badge.svg?branch=master)
4
+ [![Coverage Status](https://coveralls.io/repos/github/arashm/PoParser/badge.svg)](https://coveralls.io/github/arashm/PoParser)
5
5
  [![Code Climate](https://codeclimate.com/github/arashm/PoParser.png)](https://codeclimate.com/github/arashm/PoParser)
6
6
  [![Gem Version](https://badge.fury.io/rb/PoParser.svg)](http://badge.fury.io/rb/PoParser)
7
7
 
@@ -175,6 +175,12 @@ entry.to_h
175
175
  entry.to_s
176
176
  ```
177
177
 
178
+ To remove an entry from the PO, use `PO#delete`
179
+
180
+ ```ruby
181
+ po.delete(entry)
182
+ ```
183
+
178
184
  ### Searching
179
185
 
180
186
  `PO` is an `Enumerable`. All exciting methods from `Enumerable` are available in `PO`. The `PO` yields `Entry`.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # External Libs
2
4
  require 'simple_po_parser'
3
5
 
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PoParser
2
4
  class Comment
3
5
  attr_accessor :type, :value
4
6
 
5
7
  def initialize(type, value)
6
8
  @type = type
7
- @value = value
9
+ @value = value
8
10
 
9
- if @type.to_s =~ /^previous_/ # these behave more like messages
10
- remove_empty_line
11
- end
11
+ # these behave more like messages
12
+ remove_empty_line if /^previous_/.match?(@type.to_s)
12
13
  end
13
14
 
14
15
  def to_s(with_label = false)
15
16
  return to_str unless with_label
17
+
16
18
  if @value.is_a? Array
17
- if @type.to_s =~ /^previous_/ # these behave more like messages
19
+ if /^previous_/.match?(@type.to_s) # these behave more like messages
18
20
  string = ["#{COMMENTS_LABELS[@type]} \"\"\n"]
19
21
  @value.each do |str|
20
22
  string << "#| \"#{str}\"\n".gsub(/[\p{Blank}]+$/, '')
@@ -27,7 +29,7 @@ module PoParser
27
29
  end
28
30
  return string.join
29
31
  else
30
- if @type.to_s =~ /^previous_/ # these behave more like messages
32
+ if /^previous_/.match?(@type.to_s) # these behave more like messages
31
33
  "#{COMMENTS_LABELS[@type]} \"#{@value}\"\n".gsub(/[\p{Blank}]+$/, '')
32
34
  else
33
35
  # removes the space but not newline at the end
@@ -38,7 +40,7 @@ module PoParser
38
40
 
39
41
  def to_str
40
42
  if @value.is_a?(Array)
41
- if @type.to_s =~ /^previous_/ # these behave more like messages
43
+ if /^previous_/.match?(@type.to_s) # these behave more like messages
42
44
  @value.join
43
45
  else
44
46
  @value.join("\n")
@@ -53,10 +55,9 @@ module PoParser
53
55
  end
54
56
 
55
57
  private
58
+
56
59
  def remove_empty_line
57
- if @value.is_a? Array
58
- @value.shift if @value.first == ''
59
- end
60
+ @value.shift if @value.is_a?(Array) && @value.first == ''
60
61
  end
61
62
  end
62
63
  end
@@ -1,34 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PoParser
2
4
  COMMENTS_LABELS = {
3
- :translator_comment => '#',
4
- :extracted_comment => '#.',
5
- :reference => '#:',
6
- :flag => '#,',
7
- :previous_msgctxt => '#| msgctxt',
8
- :previous_msgid => '#| msgid',
9
- :previous_msgid_plural => '#| msgid_plural',
10
- :obsolete => '#~'
11
- }
5
+ translator_comment: '#',
6
+ extracted_comment: '#.',
7
+ reference: '#:',
8
+ flag: '#,',
9
+ previous_msgctxt: '#| msgctxt',
10
+ previous_msgid: '#| msgid',
11
+ previous_msgid_plural: '#| msgid_plural',
12
+ obsolete: '#~',
13
+ }.freeze
12
14
 
13
15
  ENTRIES_LABELS = {
14
- :msgctxt => 'msgctxt',
15
- :msgid => 'msgid',
16
- :msgid_plural => 'msgid_plural',
17
- :msgstr => 'msgstr'
18
- }
16
+ msgctxt: 'msgctxt',
17
+ msgid: 'msgid',
18
+ msgid_plural: 'msgid_plural',
19
+ msgstr: 'msgstr',
20
+ }.freeze
19
21
 
20
22
  LABELS = COMMENTS_LABELS.merge(ENTRIES_LABELS).keys
21
23
 
22
24
  HEADER_LABELS = {
23
- :pot_creation_date => "POT-Creation-Date",
24
- :po_revision_date => "PO-Revision-Date",
25
- :project_id => "Project-Id-Version",
26
- :report_to => "Project-Id-Version",
27
- :last_translator => "Last-Translator",
28
- :team => "Language-Team",
29
- :language => "Language",
30
- :charset => "Content-Type",
31
- :encoding => "Content-Transfer-Encoding",
32
- :plural_forms => "Plural-Forms"
33
- }
25
+ pot_creation_date: 'POT-Creation-Date',
26
+ po_revision_date: 'PO-Revision-Date',
27
+ project_id: 'Project-Id-Version',
28
+ report_to: 'Project-Id-Version',
29
+ last_translator: 'Last-Translator',
30
+ team: 'Language-Team',
31
+ language: 'Language',
32
+ charset: 'Content-Type',
33
+ encoding: 'Content-Transfer-Encoding',
34
+ plural_forms: 'Plural-Forms',
35
+ }.freeze
34
36
  end
@@ -1,66 +1,49 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PoParser
2
- class Entry
3
- # TODO: raise error if a label is not known
4
+ # A single translation entity in a PO file
5
+ class Entry # rubocop:disable Metrics/ClassLength
4
6
  def initialize(args = {})
5
7
  # Defining all instance variables to prevent warnings
6
- LABELS.each do |label|
7
- instance_variable_set "@#{label.to_s}".to_sym, nil
8
- end
9
-
10
- # Set passed arguments
11
- args.each do |name, value|
12
- raise(ArgumentError, "Unknown label #{name}") if !valid_label? name
13
- set_instance_variable(name, value)
14
- end
15
-
8
+ define_labels_instance_variables
9
+ define_args_instance_variables(args)
16
10
  define_writer_methods(COMMENTS_LABELS, 'Comment')
17
11
  define_writer_methods(ENTRIES_LABELS, 'Message')
18
12
  define_reader_methods
19
-
20
- self.class.send(:alias_method, :translate, :msgstr=)
21
- self.class.send(:alias_method, :cached, :obsolete)
22
- self.class.send(:alias_method, :cached=, :obsolete=)
23
- # alias for backward compatibility of this typo
24
- self.class.send(:alias_method, :refrence, :reference)
25
- self.class.send(:alias_method, :refrence=, :reference=)
26
- if self.obsolete?
27
- obsolete_content = SimplePoParser.parse_message(obsolete.value.join("\n").gsub(/^\|/, "#|"))
28
- obsolete_content.each do |name, value|
29
- raise(ArgumentError, "Unknown label #{name}") if !valid_label? name
30
- set_instance_variable(name, value)
31
- end
32
- end
13
+ define_aliases
14
+ define_obsolete_instance_variables
33
15
  end
34
16
 
35
17
  # If entry doesn't have any msgid, it's probably a obsolete entry that is
36
- # kept by the program for later use. These entries will usually start with: #~
18
+ # kept by the program for later use. These entries will usually start
19
+ # with: #~
37
20
  #
38
21
  # @return [Boolean]
39
22
  def obsolete?
40
23
  !@obsolete.nil?
41
24
  end
42
- alias_method :cached?, :obsolete?
25
+ alias cached? obsolete?
43
26
 
44
27
  # Checks if the entry is untraslated
45
28
  #
46
29
  # @return [Boolean]
47
30
  def untranslated?
48
31
  return false if obsolete? || fuzzy?
49
- if @msgstr.is_a? Array
50
- return @msgstr.map {|ms| ms.str}.join.empty?
51
- end
32
+ return @msgstr.map(&:str).join.empty? if @msgstr.is_a? Array
33
+
52
34
  @msgstr.nil? || @msgstr.str.empty?
53
35
  end
54
- alias_method :incomplete? , :untranslated?
36
+ alias incomplete? untranslated?
55
37
 
56
38
  # Checks if the entry is translated
57
39
  #
58
40
  # @return [Boolean]
59
41
  def translated?
60
42
  return false if obsolete? || fuzzy?
61
- not untranslated?
43
+
44
+ !untranslated?
62
45
  end
63
- alias_method :complete? , :translated?
46
+ alias complete? translated?
64
47
 
65
48
  # Checks if the entry is plural
66
49
  #
@@ -74,10 +57,12 @@ module PoParser
74
57
  # @return [Boolean]
75
58
  def fuzzy?
76
59
  return false if obsolete?
77
- @flag.to_s.match('fuzzy') ? true : false
60
+
61
+ @flag.to_s.match?('fuzzy') ? true : false
78
62
  end
79
63
 
80
64
  # Flag the entry as Fuzzy
65
+ #
81
66
  # @return [Entry]
82
67
  def flag_as_fuzzy
83
68
  @flag = 'fuzzy'
@@ -87,58 +72,54 @@ module PoParser
87
72
  # Set flag to a custom string
88
73
  def flag_as(flag)
89
74
  raise ArgumentError if flag.class != String
75
+
90
76
  @flag = flag
91
77
  end
92
78
 
93
79
  # Convert entry to a hash key value
80
+ #
94
81
  # @return [Hash]
95
82
  def to_h
96
- hash = {}
97
- instance_variables.each do |label|
83
+ instance_variables.each_with_object({}) do |label, hash|
98
84
  object = instance_variable_get(label)
99
85
  # If it's a plural msgstr
100
- if object.is_a? Array
86
+ if object.is_a?(Array)
101
87
  object.each do |entry|
102
- hash[entry.type] = entry.to_s if not entry.nil?
88
+ hash[entry.type] = entry.to_s unless entry.nil?
103
89
  end
104
90
  else
105
- hash[object.type] = object.to_s if not object.nil?
91
+ hash[object.type] = object.to_s unless object.nil?
106
92
  end
107
93
  end
108
- hash
109
94
  end
110
95
 
111
96
  # Convert entry to a string
97
+ #
112
98
  # @return [String]
113
99
  def to_s
114
- lines = []
115
- LABELS.each do |label|
100
+ LABELS.each_with_object([]) do |label, arr|
116
101
  object = instance_variable_get("@#{label}".to_sym)
117
102
  # If it's a plural msgstr
118
- if object.is_a? Array
119
- object.each do |entry|
120
- lines << entry.to_s(true) if not entry.nil?
121
- end
103
+ if object.is_a?(Array)
104
+ arr.push(*object.map { |entry| entry.to_s(true) }.compact)
122
105
  else
123
- lines << object.to_s(true) if not object.nil?
106
+ arr << object.to_s(true) unless object.nil?
124
107
  end
125
- end
126
-
127
- lines.join
108
+ end.join
128
109
  end
129
110
 
130
111
  def inspect
131
112
  to_s
132
113
  end
133
114
 
134
- private
115
+ private
135
116
 
136
117
  def set_instance_variable(name, value)
137
118
  if COMMENTS_LABELS.include? name
138
- instance_variable_set "@#{name.to_s}".to_sym, Comment.new(name, value)
119
+ instance_variable_set "@#{name}".to_sym, Comment.new(name, value)
139
120
  elsif ENTRIES_LABELS.include? name
140
- instance_variable_set "@#{name.to_s}".to_sym, Message.new(name, value)
141
- elsif name.to_s.match(/^msgstr\[[0-9]\]/)
121
+ instance_variable_set "@#{name}".to_sym, Message.new(name, value)
122
+ elsif /^msgstr\[[0-9]\]/.match?(name.to_s)
142
123
  # If it's a plural msgstr
143
124
  @msgstr ||= []
144
125
  @msgstr << Message.new(name, value)
@@ -147,29 +128,34 @@ module PoParser
147
128
 
148
129
  def define_writer_methods(labels, object)
149
130
  object = PoParser.const_get(object)
150
- labels.each do |type, mark|
151
- unless Entry.method_defined? "#{type}=".to_sym
152
- self.class.send(:define_method, "#{type}=".to_sym, lambda { |val|
153
- if instance_variable_get("@#{type}".to_sym).is_a? object
154
- klass = instance_variable_get "@#{type}".to_sym
155
- klass.type = type
156
- klass.value = val
157
- else
158
- instance_variable_set "@#{type}".to_sym, object.new(type, val)
159
- end
160
- # return value
161
- instance_variable_get "@#{type}".to_sym
162
- })
163
- end
131
+
132
+ labels.each do |type, _mark|
133
+ next if Entry.method_defined?("#{type}=".to_sym)
134
+
135
+ define_writer_method(type, object)
164
136
  end
165
137
  end
166
138
 
139
+ def define_writer_method(type, object)
140
+ self.class.send(:define_method, "#{type}=".to_sym, lambda { |val|
141
+ if instance_variable_get("@#{type}".to_sym).is_a? object
142
+ klass = instance_variable_get "@#{type}".to_sym
143
+ klass.type = type
144
+ klass.value = val
145
+ else
146
+ instance_variable_set "@#{type}".to_sym, object.new(type, val)
147
+ end
148
+ # return value
149
+ instance_variable_get "@#{type}".to_sym
150
+ })
151
+ end
152
+
167
153
  def define_reader_methods
168
154
  LABELS.each do |label|
169
- unless Entry.method_defined? "#{label}".to_sym
170
- self.class.send(:define_method, label.to_sym) do
171
- instance_variable_get "@#{label}".to_sym
172
- end
155
+ next if Entry.method_defined? label.to_s.to_sym
156
+
157
+ self.class.send(:define_method, label.to_sym) do
158
+ instance_variable_get "@#{label}".to_sym
173
159
  end
174
160
  end
175
161
  end
@@ -177,5 +163,41 @@ module PoParser
177
163
  def valid_label?(label)
178
164
  !(label =~ /^msgstr\[[0-9]\]/).nil? || LABELS.include?(label)
179
165
  end
166
+
167
+ def define_labels_instance_variables
168
+ LABELS.each { |label| instance_variable_set("@#{label}".to_sym, nil) }
169
+ end
170
+
171
+ def define_obsolete_instance_variables
172
+ return unless obsolete?
173
+
174
+ obsolete_content = SimplePoParser.parse_message(
175
+ obsolete.value.join("\n").gsub(/^\|/, '#|'),
176
+ )
177
+
178
+ obsolete_content.each do |name, value|
179
+ raise(ArgumentError, "Unknown label #{name}") unless valid_label? name
180
+
181
+ set_instance_variable(name, value)
182
+ end
183
+ end
184
+
185
+ def define_args_instance_variables(args)
186
+ # Set passed arguments
187
+ args.each do |name, value|
188
+ raise(ArgumentError, "Unknown label #{name}") unless valid_label? name
189
+
190
+ set_instance_variable(name, value)
191
+ end
192
+ end
193
+
194
+ def define_aliases
195
+ self.class.send(:alias_method, :translate, :msgstr=)
196
+ self.class.send(:alias_method, :cached, :obsolete)
197
+ self.class.send(:alias_method, :cached=, :obsolete=)
198
+ # alias for backward compatibility of this typo
199
+ self.class.send(:alias_method, :refrence, :reference)
200
+ self.class.send(:alias_method, :refrence=, :reference=)
201
+ end
180
202
  end
181
203
  end