rgettext_poedit 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61519ab6f494dc5c7ca8e5d4d670f3b5d5d6c939
4
+ data.tar.gz: 55e1e1a744f459bcbaed2f87f5d708765dd657a3
5
+ SHA512:
6
+ metadata.gz: 160b4fe13a4e917e10ed88c52bbcaaff27e5c3393fb1c2626343715d3bad8f440c8e6868f738a4dba48a72bd6c8d9615bd5dc43ad559e7bf2240771fa73a9289
7
+ data.tar.gz: ad36d74c05c8480ca0a38c02603db123d35f191e169e8d5f111eccb523c0a50736574e9e206ebc46840d77f09da4ac4523531512ba9fca1d636031babf56949c
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "knjrbfw"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.0"
13
+ gem "jeweler", "~> 2.0.1"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ datet (0.0.25)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ faraday (0.9.0)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.2.6)
12
+ github_api (0.11.3)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.1)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 1.2)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.0)
19
+ oauth2
20
+ hashie (2.1.0)
21
+ highline (1.6.21)
22
+ http2 (0.0.23)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (0.1.11)
34
+ multi_json (>= 1.5)
35
+ knjrbfw (0.0.108)
36
+ datet
37
+ http2
38
+ php4r
39
+ ruby_process
40
+ tsafe
41
+ wref
42
+ mini_portile (0.5.3)
43
+ multi_json (1.9.2)
44
+ multi_xml (0.5.5)
45
+ multipart-post (2.0.0)
46
+ nokogiri (1.6.1)
47
+ mini_portile (~> 0.5.0)
48
+ oauth2 (0.9.3)
49
+ faraday (>= 0.8, < 0.10)
50
+ jwt (~> 0.1.8)
51
+ multi_json (~> 1.3)
52
+ multi_xml (~> 0.5)
53
+ rack (~> 1.2)
54
+ php4r (0.0.4)
55
+ datet
56
+ http2
57
+ string-strtr
58
+ rack (1.5.2)
59
+ rake (10.2.2)
60
+ rdoc (3.12.2)
61
+ json (~> 1.4)
62
+ ruby_process (0.0.9)
63
+ tsafe
64
+ wref
65
+ string-strtr (0.0.3)
66
+ thread_safe (0.3.3)
67
+ tsafe (0.0.11)
68
+ wref (0.0.6)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler (~> 1.0)
75
+ jeweler (~> 2.0.1)
76
+ knjrbfw
77
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Kasper Johansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = rgettext_poedit
2
+
3
+ This Gem can help the application POEdit parse .erb and .haml files for easy translations.
4
+
5
+ Configure POedit like this:
6
+
7
+ New parser with name "Ruby".
8
+ List of extensions: *.rb; *.rhtml; *.erb; *.haml
9
+ Command for parsing: rgettext_poedit %F -o %o
10
+ Element in list for data files: %f
11
+
12
+ == Contributing to rgettext_poedit
13
+
14
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
15
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
16
+ * Fork the project.
17
+ * Start a feature/bugfix branch.
18
+ * Commit and push until you are happy with your contribution.
19
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
20
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2014 Kasper Johansen. See LICENSE.txt for
25
+ further details.
26
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "rgettext_poedit"
18
+ gem.homepage = "http://github.com/kaspernj/rgettext_poedit"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Scanning of source files to generate .po files to work with application like POEdit.}
21
+ gem.description = %Q{Scanning of source files to generate .po files to work with application like POEdit.}
22
+ gem.email = "k@spernj.org"
23
+ gem.authors = ["Kasper Johansen"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "rgettext_poedit #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "#{__dir__}/../lib/rgettext_poedit"
5
+
6
+
7
+ # Logging.
8
+ $fp_log = File.open("/tmp/rgettext_poedit.log", "a")
9
+ def debug(str)
10
+ puts "#{str}" if $debug
11
+ $fp_log.puts str
12
+ end
13
+
14
+
15
+ # Log initial stuff for debugging.
16
+ debug "ARGV: #{ARGV.join(", ")}"
17
+ debug "Executed command: #{Knj::Os.executed_cmd}"
18
+ debug "ENV: #{ENV.to_hash}"
19
+
20
+
21
+ # Parse arguments.
22
+ files = []
23
+ skipnext = false
24
+ ofn = nil
25
+
26
+ count = 0
27
+ ARGV.each do |value|
28
+ if skipnext
29
+ skipnext = false
30
+ next
31
+ end
32
+
33
+ skipnext = false
34
+
35
+ if value == "-o"
36
+ ofn = ARGV[count + 1]
37
+ skipnext = true
38
+ elsif value == "--debug"
39
+ $debug = true
40
+ else
41
+ files << value
42
+ end
43
+
44
+ count += 1
45
+ end
46
+
47
+ rgp = RgettextPoedit.new(
48
+ :files => files,
49
+ :output_filepath => ofn
50
+ )
51
+ rgp.parse_files
52
+ rgp.write_file
@@ -0,0 +1,97 @@
1
+ require "knjrbfw"
2
+
3
+ class RgettextPoedit
4
+ def initialize(args)
5
+ @args = args
6
+ @files = args[:files]
7
+ @translations = {}
8
+ @method_names = ["_", "gettext"]
9
+ @valid_beginning = '(^|\s+|\(|\{)'
10
+ end
11
+
12
+ def parse_files
13
+ raise "No files was given." if !@files || @files.empty?
14
+
15
+ @files.each do |filepath|
16
+ parse_filepath(filepath)
17
+ end
18
+ end
19
+
20
+ def write_file
21
+ raise "No output-filepath was given." unless @args[:output_filepath]
22
+
23
+ File.open(@args[:output_filepath], "w") do |fp|
24
+ fp.write(generate_output)
25
+ end
26
+ end
27
+
28
+ def generate_output
29
+ # Generate and write output.
30
+ @output = ""
31
+ @translations.each do |translation, data|
32
+ @output << "\n" if @output.length > 0
33
+
34
+ data[:files].each do |file|
35
+ @output << "#: #{file[:filepath]}:#{file[:line_no]}\n"
36
+ end
37
+
38
+ @output << "msgid \"#{translation}\"\n"
39
+ @output << "msgstr \"\"\n"
40
+ end
41
+
42
+ return @output
43
+ end
44
+
45
+ private
46
+
47
+ # Opens a file, reads the content while keeping track of line-numbers and saves found translations.
48
+ def parse_filepath(filepath)
49
+ File.open(filepath, "r") do |fp|
50
+ line_no = 0
51
+ fp.each_line do |line|
52
+ line_no += 1
53
+ next if should_skip_line(filepath, line_no, line)
54
+ parse_content(filepath, line_no, line)
55
+ end
56
+ end
57
+ end
58
+
59
+ # Scans content for translations and saves them.
60
+ def parse_content(filepath, line_no, content)
61
+ @method_names.each do |method_name|
62
+ # Scan for the various valid formats.
63
+ content.scan(/#{@valid_beginning}#{Regexp.escape(method_name)}\s*\("(.+?)"/) do |match|
64
+ add_translation(filepath, line_no, match[1])
65
+ end
66
+
67
+ content.scan(/#{@valid_beginning}#{Regexp.escape(method_name)}\s*"(.+?)"/) do |match|
68
+ add_translation(filepath, line_no, match[1])
69
+ end
70
+
71
+ content.scan(/#{@valid_beginning}#{Regexp.escape(method_name)}\s*\('(.+?)'/) do |match|
72
+ add_translation(filepath, line_no, match[1])
73
+ end
74
+
75
+ content.scan(/#{@valid_beginning}#{Regexp.escape(method_name)}\s*'(.+?)'/) do |match|
76
+ add_translation(filepath, line_no, match[1])
77
+ end
78
+ end
79
+ end
80
+
81
+ def should_skip_line(filepath, line_no, line)
82
+ # Skip the line if it is a comment in Haml.
83
+ if File.extname(filepath) == ".haml" && line.match(/^(\s*)-(\s*)#/)
84
+ return true
85
+ end
86
+
87
+ return false
88
+ end
89
+
90
+ def add_translation(filepath, line_no, translation)
91
+ if !@translations.key?(translation)
92
+ @translations[translation] = {:files => []}
93
+ end
94
+
95
+ @translations[translation][:files] << {:filepath => filepath, :line_no => line_no}
96
+ end
97
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RgettextPoedit" do
4
+ let(:rgp){ RgettextPoedit.new({}) }
5
+
6
+ it "can parse various forms" do
7
+ lines = [
8
+ " _('Test 1 %{name}', :name) \n",
9
+ " _ 'Test 2 %{name}', :name \n",
10
+ " _'Test 3 %{name}', :name \n",
11
+ ' _("Test 4 %{name}", :name) ',
12
+ ' _ "Test 5 %{name}", :name ',
13
+ ' _"Test 6 %{name}", :name ',
14
+ ' _"Test 7" ',
15
+ " _'Test 8' \n",
16
+ " str = \"Hejsa \#{_('Test 9')} "
17
+ ]
18
+
19
+ lines.each do |line|
20
+ rgp.__send__(:parse_content, nil, nil, line)
21
+ end
22
+
23
+ strs = rgp.instance_variable_get(:@translations)
24
+
25
+ strs.keys.should include "Test 1 %{name}"
26
+ strs.keys.should include "Test 2 %{name}"
27
+ strs.keys.should include "Test 3 %{name}"
28
+ strs.keys.should include "Test 4 %{name}"
29
+ strs.keys.should include "Test 5 %{name}"
30
+ strs.keys.should include "Test 6 %{name}"
31
+ strs.keys.should include "Test 7"
32
+ strs.keys.should include "Test 8"
33
+ strs.keys.should include "Test 9"
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'rgettext_poedit'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgettext_poedit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Johansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: knjrbfw
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ description: Scanning of source files to generate .po files to work with application
70
+ like POEdit.
71
+ email: k@spernj.org
72
+ executables:
73
+ - rgettext_poedit
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - .rspec
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - VERSION
87
+ - bin/rgettext_poedit
88
+ - lib/rgettext_poedit.rb
89
+ - spec/rgettext_poedit_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: http://github.com/kaspernj/rgettext_poedit
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Scanning of source files to generate .po files to work with application like
115
+ POEdit.
116
+ test_files: []