q_translate 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /nbproject/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -- color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in q_translate.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mathieu Gagné
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # QTranslate
2
+
3
+ Extends String with a 'translate' method. Returned value is the according translated text for a Wordpress Post translated by QTranslate plugin.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'q_translate'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install q_translate
18
+
19
+ ## Usage
20
+
21
+ Extends String with a 'translate' method. Returned value is the according translated text for a Wordpress Post translated by QTranslate plugin. Useful for Wordpress integration in a Rails app where the admin bloggin side is handled by Wordpress Engine. The default value if translation is not provided is English.
22
+
23
+
24
+ ### Uses locale
25
+
26
+ $ WpPost.post_title
27
+ $ => "<!--:en-->And this is how the Universe ended.<!--:--><!--:fr-->Et c'est ainsi que l'univers connu cessa d'exister.<!--:-->"
28
+ $ I18n.locale = :en
29
+ $ WpPost.post_title.translate
30
+ $ => "And this is how the Universe ended."
31
+
32
+ ### Uses default locale if it has not been translated yet.
33
+
34
+ $ WpPost.post_title
35
+ $ => "<!--:en-->And this is how the Universe ended.<!--:-->"
36
+ $ I18n.locale = :fr
37
+ $ WpPost.post_title.translate
38
+ $ => "And this is how the Universe ended."
39
+
40
+ ### Spits the same text out if no translation tags are applied
41
+
42
+ $ WpPost.post_title
43
+ $ => "And this is how the Universe ended."
44
+ $ I18n.locale = :fr
45
+ $ WpPost.post_title.translate
46
+ $ => "And this is how the Universe ended."
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module QTranslate
2
+ VERSION = "0.0.1.alpha"
3
+ end
@@ -0,0 +1,40 @@
1
+ require "q_translate/version"
2
+
3
+ module QTranslate
4
+
5
+ class Translation
6
+
7
+ attr_accessor :original
8
+
9
+ def initialize text
10
+ @original = text
11
+ end
12
+
13
+ def locale
14
+ I18n.locale
15
+ end
16
+
17
+ def translate
18
+ return @original if @original.blank?
19
+ if translations.has_key? locale
20
+ translations[locale]
21
+ elsif translations.has_key? I18n.default_locale
22
+ translations[I18n.default_locale]
23
+ else
24
+ @original
25
+ end
26
+ end
27
+
28
+ def translations
29
+ @translations = {}
30
+ @original.split('<!--:-->').each do |t|
31
+ t.match(/^<!--:([\w]{2})/) do |lang|
32
+ @translations[lang[1].to_sym] = t.gsub(/<!--:#{lang[1]}-->(.*)/, '\1')
33
+ end
34
+ end
35
+ @translations
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,18 @@
1
+ clean=
2
+ clobber=
3
+ clobber_package=
4
+ clobber_rdoc=
5
+ doc=
6
+ doc/rdoc=
7
+ doc/rdoc/index.html=
8
+ gem=
9
+ package=
10
+ pkg=
11
+ pkg/q_translate-0.0.1=
12
+ pkg/q_translate-0.0.1.gem=
13
+ pkg/q_translate-0.0.1.tgz=
14
+ pkg/q_translate-0.0.1.zip=
15
+ rdoc=
16
+ repackage=
17
+ rerdoc=
18
+ test=
@@ -0,0 +1,6 @@
1
+ main.file=
2
+ platform.active=Ruby_0
3
+ source.encoding=UTF-8
4
+ spec.src.dir=spec
5
+ src.dir=lib
6
+ test.src.dir=test
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://www.netbeans.org/ns/project/1">
3
+ <type>org.netbeans.modules.ruby.rubyproject</type>
4
+ <configuration>
5
+ <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
6
+ <name>q_translate</name>
7
+ <source-roots>
8
+ <root id="src.dir"/>
9
+ </source-roots>
10
+ <test-roots>
11
+ <root id="test.src.dir"/>
12
+ <root id="spec.src.dir"/>
13
+ </test-roots>
14
+ </data>
15
+ </configuration>
16
+ </project>
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/q_translate/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "q_translate"
6
+ gem.authors = ["Mathieu Gagné"]
7
+ gem.email = ["mathieu@orangebrule.com"]
8
+ gem.description = %q{Extends String with a 'translate' method. Returned value is the according translated text for a Wordpress Post translated by QTranslate plugin.}
9
+ gem.summary = %q{Extends String with a 'translate' method. Returned value is the according translated text for a Wordpress Post translated by QTranslate plugin. Useful for Wordpress integration in a Rails app where the admin bloggin side is handled by Wordpress Engine. The default value if translation is not provided is English.}
10
+ gem.homepage = "http://github.com/orangebrule/q-translate"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ["lib"]
16
+ gem.version = QTranslate::VERSION
17
+
18
+ gem.add_development_dependency 'rspec'
19
+
20
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ TEST_STRING = "<!--:en-->And this is how the Universe ended.<!--:--><!--:fr-->Et c'est ainsi que l'univers connu cessa d'exister.<!--:-->"
4
+
5
+ describe QTranslate::Translation do
6
+
7
+ before :each do
8
+ @text = QTranslate::Translation.new(TEST_STRING)
9
+ end
10
+
11
+ describe '.translate' do
12
+
13
+ describe 'if translated' do
14
+
15
+ it "should return French translation if locale is French" do
16
+ I18n.locale = :fr
17
+ @text.translate.should match "Et c'est ainsi que l'univers connu cessa d'exister."
18
+ end
19
+
20
+ it "should return English translation if locale is English" do
21
+ I18n.locale = :en
22
+ @text.translate.should match "And this is how the Universe ended."
23
+ end
24
+
25
+ end
26
+
27
+ describe 'if not translated' do
28
+
29
+ it "should use default locale" do
30
+ I18n.locale = :es
31
+ @text.translate.should match 'And this is how the Universe ended.'
32
+ end
33
+
34
+ it "should return itself" do
35
+ @text = QTranslate::Translation.new("Whatever man!")
36
+ @text.translate.should match "Whatever man!"
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ describe '.translations' do
43
+
44
+ it "should return a hash of locales and associated translated text" do
45
+ @text.translations.should be_a Hash
46
+ @text.translations.should have(2).keys
47
+ @text.translations[:en].should match "And this is how the Universe ended."
48
+ @text.translations[:fr].should match "Et c'est ainsi que l'univers connu cessa d'exister."
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,2 @@
1
+ require 'rails'
2
+ require 'q_translate'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: q_translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Mathieu Gagné
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Extends String with a 'translate' method. Returned value is the according
31
+ translated text for a Wordpress Post translated by QTranslate plugin.
32
+ email:
33
+ - mathieu@orangebrule.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .rspec
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - lib/q_translate.rb
45
+ - lib/q_translate/version.rb
46
+ - nbproject/private/rake-d.txt
47
+ - nbproject/project.properties
48
+ - nbproject/project.xml
49
+ - q_translate.gemspec
50
+ - spec/q_translate/q_translate_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: http://github.com/orangebrule/q-translate
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.1
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.18
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Extends String with a 'translate' method. Returned value is the according
76
+ translated text for a Wordpress Post translated by QTranslate plugin. Useful for
77
+ Wordpress integration in a Rails app where the admin bloggin side is handled by
78
+ Wordpress Engine. The default value if translation is not provided is English.
79
+ test_files:
80
+ - spec/q_translate/q_translate_spec.rb
81
+ - spec/spec_helper.rb