stamp-l10n 0.1.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: fda01dd55be5569287bc960fbc585cf55d07e720
4
+ data.tar.gz: e152739aa11bcf2061760ba15321550cbd9af580
5
+ SHA512:
6
+ metadata.gz: 2c3043a3f47c3a519bd4dd673c2d33707434bda7c8f4d654e648bebeab5474305d446f53740315c4f5ec25505a2b987a896b60b613a1cdf83229dccd0b654662
7
+ data.tar.gz: d0fad2be32f5ea005f7cdce40e04b3141d83571a112749e13e9262fff9f16a53b97cd186d256dae397121ddfcfe76728c5353d838473bf17aeb787a12dbd9f58
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ ExtraDetails: true
4
+ TargetRubyVersion: 2.2
5
+
6
+ Metrics/LineLength:
7
+ Max: 120
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/FileName:
13
+ Exclude:
14
+ - 'lib/stamp-l10n.rb'
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/AbcSize:
20
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.10
4
+ - 2.2.6
5
+ - 2.3.3
6
+ - 2.4.0
7
+ - ruby-head
@@ -0,0 +1,74 @@
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, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ 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 dave@tanda.co. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stamp-l10n.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dave Allie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # StampL10n
2
+
3
+ [![Build Status](https://travis-ci.org/TandaHQ/stamp-l10n.svg?branch=master)](https://travis-ci.org/TandaHQ/stamp-l10n)
4
+
5
+ Successor to [stamp-i18n](https://github.com/karpiu/stamp-i18n), designed to work with newer versions of [stamp](https://github.com/jeremyw/stamp).
6
+
7
+ Uses Rails Internationalization to bring stamp to all locales.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ # Stamp changes a lot between versions, so make sure to pin its version
15
+ gem 'stamp', '= 0.6.0'
16
+ gem 'stamp-l10n'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Before using
24
+
25
+ This gem uses i18n translation mechnism, which means before using it, first we need to add proper translation files to locales folder and then setup i18n configuration. Example YML files used for testing is written in few various languages and are located in ./locale folder. Look for more examples here: https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
26
+
27
+ ## Usage
28
+
29
+ Same as [stamp](https://github.com/jeremyw/stamp), but gives the option of `locale_stamp`, or `l_stamp` (an alias) for when you need your stamped content to be localized.
30
+
31
+ ```ruby
32
+ date = Date.new(2017, 02, 22)
33
+ date.stamp('Tuesday 12th March')
34
+ #=> "Wednesday 22nd February"
35
+ ```
36
+
37
+ Using the new `locale_stamp` method:
38
+
39
+ ```ruby
40
+ date = Date.new(2017, 02, 22)
41
+ date.locale_stamp('Tuesday 12th March') # default locale is :de
42
+ #=> "Mittwoch 22nd Februar"
43
+ date.l_stamp('Tuesday 12th March') # default locale is :pl
44
+ #=> "środa 22nd luty"
45
+ ```
46
+
47
+ You can also optionally override the locale used:
48
+
49
+ ```ruby
50
+ date = Date.new(2017, 02, 22)
51
+ date.locale_stamp('Tuesday 12th March', :de) # default locale is :en
52
+ #=> "Mittwoch 22nd Februar"
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tandahq/stamp-l10n. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ module StampL10n
2
+ module Emitters
3
+ module AmPmExtension
4
+ module ClassMethods
5
+ def lowercase(locale = I18n.locale)
6
+ ::Stamp::Emitters::AmPm.new { |v| I18n.t(v, scope: 'time', locale: locale) }
7
+ end
8
+
9
+ def uppercase(locale = I18n.locale)
10
+ ::Stamp::Emitters::AmPm.new { |v| I18n.t(v, scope: 'time', locale: locale).upcase }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module StampL10n
2
+ module Emitters
3
+ module LookupExtension
4
+ module ClassMethods
5
+ def month(locale = I18n.locale)
6
+ ::Stamp::Emitters::Lookup.new(:month, I18n.t('date.month_names', locale: locale))
7
+ end
8
+
9
+ def abbr_month(locale = I18n.locale)
10
+ ::Stamp::Emitters::Lookup.new(:month, I18n.t('date.abbr_month_names', locale: locale))
11
+ end
12
+
13
+ def day(locale = I18n.locale)
14
+ ::Stamp::Emitters::Lookup.new(:wday, I18n.t('date.day_names', locale: locale))
15
+ end
16
+
17
+ def abbr_day(locale = I18n.locale)
18
+ ::Stamp::Emitters::Lookup.new(:wday, I18n.t('date.abbr_day_names', locale: locale))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module StampL10n
2
+ module StampExtension
3
+ def locale_stamp(example, locale = I18n.locale)
4
+ memoize_locale_stamp_emitters(example, locale).format(self)
5
+ end
6
+ alias l_stamp locale_stamp
7
+
8
+ private
9
+
10
+ def locale_stamp_emitters(example, locale = I18n.locale)
11
+ emitters = ::Stamp::Translator.new.translate_with_locale(example, locale)
12
+ Disambiguator.new(emitters).disambiguate!
13
+ end
14
+
15
+ def memoize_stamp_emitters(example)
16
+ @@memoized_stamp_emitters ||= {} # rubocop:disable Style/ClassVars
17
+ @@memoized_stamp_emitters[example] ||= {}
18
+ @@memoized_stamp_emitters[example][nil] ||= stamp_emitters(example)
19
+ end
20
+
21
+ def memoize_locale_stamp_emitters(example, locale = I18n.locale)
22
+ @@memoized_stamp_emitters ||= {} # rubocop:disable Style/ClassVars
23
+ @@memoized_stamp_emitters[example] ||= {}
24
+ @@memoized_stamp_emitters[example][locale] ||= locale_stamp_emitters(example, locale)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ module StampL10n
2
+ module TranslatorExtension
3
+ def translate_with_locale(example, locale = I18n.locale)
4
+ # extract any substrings that look like times, like "23:59" or "8:37 am"
5
+ before, time_example, after = example.partition(::Stamp::Translator::TIME_REGEXP)
6
+
7
+ # build emitters from the example date
8
+ emitters = ::Stamp::Emitters::Composite.new
9
+ emitters << build_emitters(before.split(/\b/)) do |token|
10
+ date_emitter_with_locale(token, locale)
11
+ end
12
+
13
+ # build emitters from the example time
14
+ unless time_example.empty?
15
+ time_parts = time_example.scan(::Stamp::Translator::TIME_REGEXP).first
16
+ emitters << build_emitters(time_parts) do |token|
17
+ time_emitter_with_locale(token, locale)
18
+ end
19
+ end
20
+
21
+ # recursively process any remaining text
22
+ emitters << translate(after) unless after.empty?
23
+ emitters
24
+ end
25
+
26
+ def time_emitter_with_locale(token, locale = I18n.locale)
27
+ case token
28
+ when ::Stamp::Translator::MERIDIAN_LOWER_REGEXP
29
+ ::Stamp::Emitters::AmPm.lowercase(locale)
30
+ when ::Stamp::Translator::MERIDIAN_UPPER_REGEXP
31
+ ::Stamp::Emitters::AmPm.uppercase(locale)
32
+ else
33
+ time_emitter(token)
34
+ end
35
+ end
36
+
37
+ def date_emitter_with_locale(token, locale = I18n.locale)
38
+ case token
39
+ when ::Stamp::Translator::MONTHNAMES_REGEXP
40
+ ::Stamp::Emitters::Lookup.month(locale)
41
+ when ::Stamp::Translator::ABBR_MONTHNAMES_REGEXP
42
+ ::Stamp::Emitters::Lookup.abbr_month(locale)
43
+ when ::Stamp::Translator::DAYNAMES_REGEXP
44
+ ::Stamp::Emitters::Lookup.day(locale)
45
+ when ::Stamp::Translator::ABBR_DAYNAMES_REGEXP
46
+ ::Stamp::Emitters::Lookup.abbr_day(locale)
47
+ else
48
+ date_emitter(token)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module StampL10n
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/stamp-l10n.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'date'
2
+ require 'time'
3
+ require 'stamp'
4
+ require 'i18n'
5
+ require 'stamp-l10n/stamp_extension'
6
+ require 'stamp-l10n/translator_extension'
7
+ require 'stamp-l10n/emitters/am_pm_extension'
8
+ require 'stamp-l10n/emitters/lookup_extension'
9
+
10
+ module Stamp
11
+ prepend StampL10n::StampExtension
12
+
13
+ class Translator
14
+ prepend StampL10n::TranslatorExtension
15
+ end
16
+
17
+ module Emitters
18
+ class AmPm
19
+ class << self
20
+ prepend StampL10n::Emitters::AmPmExtension::ClassMethods
21
+ end
22
+ end
23
+ class Lookup
24
+ class << self
25
+ prepend StampL10n::Emitters::LookupExtension::ClassMethods
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Date.send(:include, Stamp)
32
+ Time.send(:include, Stamp)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stamp-l10n/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stamp-l10n'
8
+ spec.version = StampL10n::VERSION
9
+ spec.authors = ['Dave Allie']
10
+ spec.email = ['dave@tanda.co']
11
+
12
+ spec.summary = 'Uses Rails Internationalization to bring stamp to all locales.'
13
+ spec.description = 'Uses Rails Internationalization to bring stamp to all locales.'
14
+ spec.homepage = 'https://github.com/tandahq/stamp-l10n'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features|locale)/})
19
+ end
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.14'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rubocop', '~> 0.47.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_dependency 'stamp', '= 0.6.0'
27
+ spec.add_dependency 'i18n'
28
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stamp-l10n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Allie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.47.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.47.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: stamp
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: i18n
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Uses Rails Internationalization to bring stamp to all locales.
98
+ email:
99
+ - dave@tanda.co
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/stamp-l10n.rb
114
+ - lib/stamp-l10n/emitters/am_pm_extension.rb
115
+ - lib/stamp-l10n/emitters/lookup_extension.rb
116
+ - lib/stamp-l10n/stamp_extension.rb
117
+ - lib/stamp-l10n/translator_extension.rb
118
+ - lib/stamp-l10n/version.rb
119
+ - stamp-l10n.gemspec
120
+ homepage: https://github.com/tandahq/stamp-l10n
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Uses Rails Internationalization to bring stamp to all locales.
144
+ test_files: []