PoParser 1.0.3 → 1.1.0

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
2
  SHA1:
3
- metadata.gz: 8036d5aecfd813ef156edec1a8595a2351757e62
4
- data.tar.gz: c5ae7091bcd9688b6222ef1b0f184092bd47fbd3
3
+ metadata.gz: 954ba00cb0682d03951ff75fc7de053d515a621b
4
+ data.tar.gz: 40d00d176527e9c4ff109cd44dd3c46c16674a42
5
5
  SHA512:
6
- metadata.gz: 57d9bc1dce5ff0212d027de02621ab56a6e1f4e32a8ccec4df69d3e053457d571029098e820cb0117e7d9fc524deb9e8a0db106ceaea16a2a2b335f267ca7f22
7
- data.tar.gz: efcd02494737acea74a7a773d4cd551daec9ce83d5bb672e8f72e6cf08a04d095486f95460b2d88f40d6050a611f138f5300729a8fe68c3d08038186486f84db
6
+ metadata.gz: 8b1635f9d67863a2ffe25c0051b3d772d3ae595f8600fe190d152524441a4f44354b1b95929ca2b47ea46526bb80a52646919796c67610d822bdc85261bf6ffe
7
+ data.tar.gz: 1bfa4f0d0d4df93cba148577e3b803113c627758c26e1cee69de0f823d8fbf0b82dfdd912ce7c98c7b9866dbc08a1cc6a2768f2fc4e685e7415b7aafd2d6362f
data/CHANGELOG.md CHANGED
@@ -1,38 +1,54 @@
1
- ## Version 1.0.3
2
- * Add `obsolete` alias for `cached` entries. Now you can use `Po#obsolete` or `Entry#obsolete?`
1
+ 1.1.0 / 2016-12-07
2
+ ==================
3
3
 
4
- ## Version 1.0.2
5
- * Update dependencies
6
- * Handle empty lines in .po file (thanks to @roland9)
7
- * Fix translated strings stats
4
+ * fixed typo refrence, but kept it backwards compatible for entries
5
+ * [Header] skip empty header fields from to_s output with a warning
6
+ * [Parser] Allow multiple space after msgs and text
7
+ * added alias methods for entry accessors
8
8
 
9
- ## Version 1.0.1
9
+ Version 1.0.3
10
+ =============
10
11
 
11
- * Update dependencies and tests
12
+ * Add `obsolete` alias for `cached` entries. Now you can use `Po#obsolete` or `Entry#obsolete?`
12
13
 
13
- ## Version 1.0.0
14
+ Version 1.0.2
15
+ =============
14
16
 
15
- * add support for header entry
16
- * `add_entry` renamed to `add` and returns `self`
17
- * besides percentages, inspect of `po` now returns each entry count too
18
- * `po.add` now raises error if you try to add an unknown label
17
+ * Update dependencies
18
+ * Handle empty lines in .po file (thanks to @roland9)
19
+ * Fix translated strings stats
19
20
 
20
- ## Version 0.2.1
21
+ Version 1.0.1
22
+ =============
21
23
 
22
- * Add search_in method.
24
+ * Update dependencies and tests
23
25
 
24
- ## Version 0.2.0
26
+ Version 1.0.0
27
+ =============
25
28
 
26
- * Some entries in PO files are started with "#~", these entries are just kept by program for later use and are not counted as active entries. `PoParser` now supports them. We won't count them in stats or show them in Tanslated or Untranslated entries. They're just there.
29
+ * add support for header entry
30
+ * `add_entry` renamed to `add` and returns `self`
31
+ * besides percentages, inspect of `po` now returns each entry count too
32
+ * `po.add` now raises error if you try to add an unknown label
27
33
 
28
- * Added size/length methods to `PO` class. It won't count cached entries(described above).
34
+ Version 0.2.1
35
+ =============
29
36
 
30
- ## Version 0.1.1
37
+ * Add search_in method.
31
38
 
32
- * Fix bug of "str" and "to_str" on Messages
33
- * Small refactoring
39
+ Version 0.2.0
40
+ =============
34
41
 
35
- ## Version 0.1.0
42
+ * Some entries in PO files are started with "#~", these entries are just kept by program for later use and are not counted as active entries. `PoParser` now supports them. We won't count them in stats or show them in Tanslated or Untranslated entries. They're just there.
43
+ * Added size/length methods to `PO` class. It won't count cached entries(described above).
36
44
 
37
- * initial release
45
+ Version 0.1.1
46
+ =============
38
47
 
48
+ * Fix bug of "str" and "to_str" on Messages
49
+ * Small refactoring
50
+
51
+ Version 0.1.0
52
+ =============
53
+
54
+ * initial release
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ group :test do
8
8
  end
9
9
 
10
10
  group :development do
11
- gem 'pry'
11
+ gem 'pry-byebug', :platforms => :mri
12
12
  gem 'guard-rspec'
13
13
  end
14
14
 
data/README.md CHANGED
@@ -66,7 +66,7 @@ You can add a new entry to the PO file:
66
66
  ```ruby
67
67
  new_entry = {
68
68
  translator_comment: 'comment',
69
- refrence: 'refrence comment',
69
+ reference: 'reference comment',
70
70
  msgid: 'untranslated',
71
71
  msgstr: 'translated string'
72
72
  }
@@ -84,7 +84,7 @@ Adding plural string is the same:
84
84
  ```ruby
85
85
  new_entry = {
86
86
  translator_comment: 'comment',
87
- refrence: 'refrence comment',
87
+ reference: 'reference comment',
88
88
  msgid_plural: 'untranslated',
89
89
  'msgstr[0]': 'translated string',
90
90
  'msgstr[1]': 'translated string'
@@ -100,11 +100,11 @@ Each entry can have following properties (for more information see [GNU PO file
100
100
 
101
101
  ```
102
102
  translator_comment
103
- refrence
103
+ reference
104
104
  extracted_comment
105
105
  flag
106
106
  previous_untraslated_string
107
- cached
107
+ cached # obsolete entries
108
108
  msgid
109
109
  msgid_plural
110
110
  msgstr
@@ -2,7 +2,7 @@ module PoParser
2
2
  COMMENTS_LABELS = {
3
3
  :translator_comment => '#',
4
4
  :extracted_comment => '#.',
5
- :refrence => '#:',
5
+ :reference => '#:',
6
6
  :flag => '#,',
7
7
  :previous_untraslated_string => '#|',
8
8
  :cached => '#~'
@@ -18,6 +18,11 @@ module PoParser
18
18
  define_reader_methods
19
19
 
20
20
  self.class.send(:alias_method, :translate, :msgstr=)
21
+ self.class.send(:alias_method, :obsolete, :cached)
22
+ self.class.send(:alias_method, :obsolete=, :cached=)
23
+ # alias for backward compatibility of this typo
24
+ self.class.send(:alias_method, :refrence, :reference)
25
+ self.class.send(:alias_method, :refrence=, :reference)
21
26
  end
22
27
 
23
28
  # If entry doesn't have any msgid, it's probably a cached entry that is
@@ -34,6 +34,11 @@ module PoParser
34
34
  end
35
35
  string << "msgid \"\"\nmsgstr \"\""
36
36
  configs.each do |k, v|
37
+ if v.nil? || v.empty?
38
+ puts "WARNING: \"#{k}\" header field is empty and skipped"
39
+ next
40
+ end
41
+
37
42
  string << "#{k}: #{v}\n".dump
38
43
  end
39
44
  string.join("\n")
@@ -7,7 +7,7 @@ module PoParser
7
7
 
8
8
  # Comments
9
9
  rule(:comments) do
10
- refrence |
10
+ reference |
11
11
  extracted_comment | flag |
12
12
  previous_untraslated_string |
13
13
  cached |
@@ -16,14 +16,14 @@ module PoParser
16
16
 
17
17
  rule(:translator_comment) { spaced('#') >> comment_text_line.as(:translator_comment) }
18
18
  rule(:extracted_comment) { spaced('#.') >> comment_text_line.as(:extracted_comment) }
19
- rule(:refrence) { spaced('#:') >> comment_text_line.as(:refrence) }
19
+ rule(:reference) { spaced('#:') >> comment_text_line.as(:reference) }
20
20
  rule(:flag) { spaced('#,') >> comment_text_line.as(:flag) }
21
21
  rule(:previous_untraslated_string){ spaced('#|') >> comment_text_line.as(:previous_untraslated_string) }
22
22
  rule(:cached) { spaced('#~') >> comment_text_line.as(:cached) }
23
23
 
24
24
  # Entries
25
25
  rule(:entries) do
26
- msgid.as(:msgid) |
26
+ msgid.as(:msgid) |
27
27
  msgid_plural.as(:msgid_plural) |
28
28
  msgstr.as(:msgstr) |
29
29
  msgstr_plural.as(:msgstr_plural) |
@@ -39,7 +39,7 @@ module PoParser
39
39
  rule(:msgctxt) { spaced('msgctxt') >> msg_text_line >> multiline.repeat }
40
40
 
41
41
  # Helpers
42
- rule(:space) { match['[^\S\n]'] } #match only whitespace and not newline
42
+ rule(:space) { match['\p{Blank}'].repeat } #match only whitespace and not newline
43
43
  rule(:space?) { space.maybe }
44
44
  rule(:newline) { match["\n"] }
45
45
  rule(:eol) { newline | any.absent? }
@@ -65,4 +65,3 @@ module PoParser
65
65
  end
66
66
  end
67
67
  end
68
-
data/lib/poparser/po.rb CHANGED
@@ -15,7 +15,7 @@ module PoParser
15
15
  # @example
16
16
  # entry = {
17
17
  # translator_comment: 'comment',
18
- # refrence: 'refrense comment',
18
+ # reference: 'reference comment',
19
19
  # flag: 'fuzzy',
20
20
  # msgid: 'translatable string',
21
21
  # msgstr: 'translation'
@@ -1,3 +1,3 @@
1
1
  module PoParser
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -8,7 +8,7 @@ describe PoParser::Entry do
8
8
  end
9
9
 
10
10
  let(:labels) do
11
- [:refrence, :extracted_comment, :flag, :previous_untraslated_string,
11
+ [:reference, :refrence, :extracted_comment, :flag, :previous_untraslated_string,
12
12
  :translator_comment, :msgid, :msgid_plural, :msgstr, :msgctxt]
13
13
  end
14
14
 
@@ -1,13 +1,12 @@
1
- #encoding: utf-8
2
- require "spec_helper"
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
3
 
4
4
  describe PoParser::Parser do
5
5
  let(:po) { PoParser::Parser.new }
6
6
 
7
7
  context(:comments) do
8
-
9
8
  let(:tc) { po.translator_comment }
10
- let(:rc) { po.refrence }
9
+ let(:rc) { po.reference }
11
10
  let(:ec) { po.extracted_comment }
12
11
  let(:fc) { po.flag }
13
12
  let(:pusc){ po.previous_untraslated_string }
@@ -35,7 +34,6 @@ describe PoParser::Parser do
35
34
  expect(pusc).to parse("#| \"Hello,\\n\"\n")
36
35
  expect(pusc).to parse("#| \"The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is \"\n")
37
36
  end
38
-
39
37
  end
40
38
 
41
39
  context 'Entries' do
@@ -46,11 +44,13 @@ describe PoParser::Parser do
46
44
  it 'parses msgid' do
47
45
  expect(msgid).to parse "msgid \"The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is now \"\n"
48
46
  expect(msgid).to parse "msgid \"The new \"state\" of %(module)s - %(branch)s - %(domain)s (%(language)s) is now \"\n"
47
+ expect(msgid).to parse "msgid \"The new \"state\" of %(module)s - %(branch)s - %(domain)s (%(language)s) is now \"\n"
49
48
  end
50
49
 
51
50
  it 'parses msgstr' do
52
51
  expect(msgstr).to parse "msgstr \"The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is now \"\n"
53
52
  expect(msgstr).to parse "msgstr \"فعالیت نامعتبر. شاید یک نفر دیگر دقیقا قبل از شما یک فعالیت دیگر ارسال کرده ۱۲۳۱۲۳۱safda \"\n"
53
+ expect(msgstr).to parse "msgstr \"The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is now \"\n"
54
54
  end
55
55
 
56
56
  it 'parses multiline entries' do
@@ -60,10 +60,13 @@ describe PoParser::Parser do
60
60
  end
61
61
 
62
62
  it 'parses plural msgstr entries' do
63
- str = "msgstr[0] \"\""
63
+ str1 = "msgstr[0] \"\""
64
+ str2 = "msgstr[0] \"\""
65
+ str3 = "msgstr[0]\"\""
64
66
  result = [{:msgstr_plural=>{:plural_id=>"0", :text=>""}}]
65
- expect(po.parse(str)).to eq(result)
67
+ expect(po.parse(str1)).to eq(result)
68
+ expect(po.parse(str2)).to eq(result)
69
+ expect(po.parse(str3)).to eq(result)
66
70
  end
67
71
  end
68
-
69
72
  end
@@ -5,7 +5,7 @@ describe PoParser::Po do
5
5
  let (:entry) do
6
6
  {
7
7
  translator_comment: 'comment',
8
- refrence: 'refrence comment',
8
+ reference: 'reference comment',
9
9
  msgid: 'untranslated',
10
10
  msgstr: 'translated string'
11
11
  }
@@ -5,7 +5,7 @@ describe PoParser::Tokenizer do
5
5
  let(:token) { PoParser::Tokenizer.new }
6
6
  let(:po_file){ Pathname.new('spec/poparser/fixtures/tokenizer.po').realpath }
7
7
  let(:po_file_empty_line){ Pathname.new('spec/poparser/fixtures/tokenizer_empty_line.po').realpath }
8
- let(:result) { [{:refrence=>"templates:105", :msgid=>"Afrikaans", :msgstr=>"آفریقایی"}, {:flag=>"fuzzy", :msgid=>"Afrikaans", :msgstr=>"آفریقایی" }] }
8
+ let(:result) { [{:reference=>"templates:105", :msgid=>"Afrikaans", :msgstr=>"آفریقایی"}, {:flag=>"fuzzy", :msgid=>"Afrikaans", :msgstr=>"آفریقایی" }] }
9
9
 
10
10
  it 'should be able to extracts entries' do
11
11
  expect(
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'poparser'
9
9
  require 'parslet/rig/rspec'
10
10
  require 'coveralls'
11
11
  require 'awesome_print'
12
+ require 'pry'
12
13
 
13
14
  Coveralls.wear!
14
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: PoParser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arash Mousavi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet