fractual_i18n 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 129ab31c55042e1c874a3bfc3bf2fd5138b05ca12096422a3560df6996a92c5a
4
+ data.tar.gz: 65fbb964162111aeb79513a2d6400ea89bac32c58d47e00f101f64d54df5d117
5
+ SHA512:
6
+ metadata.gz: 6838fecf53905311dc16fdc8172499cf3d12dc684114956815723c0f9e452e7837b77c43c60dc8a6ea1ebf2f5dbec245654eaddcc5b195054d11a7307b26f9c1
7
+ data.tar.gz: 922b001301f42058c7f7b0c52518426a0d7daff6e1c5fa799105a9a32c744e86e336324d8b49105dc60dc1a81cd9e7e20336258ab415d864fac8435f4176b7f4
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fractual_i18n.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fractual_i18n (0.1.0)
5
+ i18n
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.1.7)
11
+ i18n (1.8.5)
12
+ concurrent-ruby (~> 1.0)
13
+ minitest (5.14.1)
14
+ rake (12.3.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ fractual_i18n!
21
+ minitest (~> 5.0)
22
+ rake (~> 12.0)
23
+
24
+ BUNDLED WITH
25
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Robert Sęk
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.
@@ -0,0 +1,38 @@
1
+ # FractualI18n
2
+
3
+ Supports loading translation files from views folder
4
+
5
+ Example:
6
+ app/views/something/show.html.erb
7
+ app/views/something/show.yml
8
+ In "show.html.erb", one can write `t(".my_key")` which will expand to translations inside "show.yml" file
9
+ via key "something.show"
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem "fractual_i18n"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ In the Rails initializer:
22
+
23
+ `I18n::Backend::Simple.include(FractualI18n::Backend)`
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/trmz/fractual_i18n.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fractual_i18n"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative "lib/fractual_i18n/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "fractual_i18n"
5
+ spec.version = FractualI18n::VERSION
6
+ spec.authors = ["Robert Sęk", "Wojciech Wnętrzak"]
7
+ spec.email = ["w.wnetrzak@gmail.com"]
8
+
9
+ spec.summary = %q{Supports loading translation files from views folder}
10
+ spec.description = %q{Supports loading translation files from views folder}
11
+ spec.homepage = "https://github.com/tiramizoo/fractual_i18n"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/tiramizoo/fractual_i18n"
17
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "i18n"
29
+ end
@@ -0,0 +1,15 @@
1
+ require "i18n"
2
+ require "fractual_i18n/version"
3
+ require "fractual_i18n/configuration"
4
+ require "fractual_i18n/backend"
5
+ require "fractual_i18n/railtie" if defined?(Rails)
6
+
7
+ module FractualI18n
8
+ def self.configuration
9
+ @configuration ||= FractualI18n::Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield configuration
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module FractualI18n::Backend
2
+ def load_yml(filename)
3
+ if (fractual_path = FractualI18n.configuration.fractual_paths.find { |path| filename.starts_with?(path) })
4
+ content = YAML.load_file(filename)
5
+ keys = filename.delete_prefix(fractual_path).delete_prefix("/").split("/")
6
+ last_key = keys.pop.delete_suffix(".yml")
7
+ keys << last_key
8
+ keys.map! { |key| key.delete_prefix("_") } # remove underscore from partial name
9
+ FractualI18n.configuration.available_locales.each_with_object({}) do |locale, translations|
10
+ next unless content[locale.to_s]
11
+
12
+ translations[locale] = keys.reverse.inject(content[locale.to_s]) { |translation, key| { key => translation } }
13
+ end
14
+ else # default
15
+ YAML.load_file(filename)
16
+ end
17
+ rescue TypeError, ScriptError, StandardError => e
18
+ raise I18n::InvalidLocaleData.new(filename, e.inspect)
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ class FractualI18n::Configuration
2
+ attr_accessor :available_locales, :fractual_paths
3
+
4
+ def initialize
5
+ @available_locales = I18n.available_locales
6
+ @fractual_paths = []
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require "rails/railtie"
2
+
3
+ class FractualI18n::Railtie < Rails::Railtie
4
+ initializer "fractual_i18n.set_fractual_paths" do |app|
5
+ FractualI18n.configuration.fractual_paths = app.config.paths["app/views"].existent
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module FractualI18n
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fractual_i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Sęk
8
+ - Wojciech Wnętrzak
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-08-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Supports loading translation files from views folder
29
+ email:
30
+ - w.wnetrzak@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - fractual_i18n.gemspec
44
+ - lib/fractual_i18n.rb
45
+ - lib/fractual_i18n/backend.rb
46
+ - lib/fractual_i18n/configuration.rb
47
+ - lib/fractual_i18n/railtie.rb
48
+ - lib/fractual_i18n/version.rb
49
+ homepage: https://github.com/tiramizoo/fractual_i18n
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/tiramizoo/fractual_i18n
54
+ source_code_uri: https://github.com/tiramizoo/fractual_i18n
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Supports loading translation files from views folder
74
+ test_files: []