activerecord_i18n 0.1.1

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
+ SHA256:
3
+ metadata.gz: f1c1b4c3a8dfe39113b3edb9a0ba187944fac123f0c92f96eda7f0b8955e3257
4
+ data.tar.gz: b00aea315a963f22ccf982cdd6453a953b6cad3b439fabf268be05df00fe1da6
5
+ SHA512:
6
+ metadata.gz: 1460dd02a056439ca86490bdd078ed60e728f98e196ae899761ed65c4457213d790f8f4128cfa29270cc7fdfa560384fd1596fa3cc527edfbc876582e719ad30
7
+ data.tar.gz: 9378a20388d0047af64a4e4d2874600a6db2e3fceaf19073277d7e85e32f728ac39d0a4459084db061f18a71c081fd3772470fa30aed157479e11e0fdd291a0f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Denis Fabien
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.md ADDED
@@ -0,0 +1,42 @@
1
+ # ActiverecordI18n
2
+ This gem was created to use db additionaly to the existing I18n.t
3
+ This gems didn't replace the standard.
4
+
5
+ If you want to replace, you can use this gem : https://github.com/svenfuchs/i18n-active_record
6
+
7
+ ## Usage
8
+ Use from view
9
+ ```
10
+ ot('mykey') # will create a key name mykey
11
+ ot('.mykey') # will create a key name <view-path>.mykey
12
+ ```
13
+
14
+ Using elsewhere from a view
15
+ ```
16
+ ActiverecordI18n::Helper.ot('mykey')
17
+ ```
18
+
19
+ ## Getting started
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'activerecord_i18n'
24
+ ```
25
+
26
+ And then execute:
27
+ ```bash
28
+ $ bundle install
29
+ ```
30
+
31
+ Or install it yourself as:
32
+ ```bash
33
+ $ gem install activerecord_i18n
34
+ ```
35
+
36
+ To install model and migration
37
+ ```bash
38
+ $ rails generate activerecord_i18n:install
39
+ ```
40
+
41
+ ## License
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ActiverecordI18n'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module ActiverecordI18n
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ActiverecordI18n
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module ActiverecordI18n
2
+ module Helper
3
+ def self.ot(key, default_value=nil)
4
+ return ActiverecordI18n.get_translation(key, default_value)
5
+ end
6
+
7
+ def ot(key, default_value=nil)
8
+ return ActiverecordI18n.get_translation(key, default_value, @current_template || nil)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module ActiverecordI18n
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ActiverecordI18n
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails'
2
+ require "active_support"
3
+ require "activerecord_i18n/railtie"
4
+ require "activerecord_i18n/helper"
5
+ require "activerecord_i18n/engine" if defined?(Rails)
6
+
7
+ module ActiverecordI18n
8
+ def self.setup
9
+ yield self
10
+ end
11
+
12
+ def self.get_translation(key, default_value=nil, current_template=nil)
13
+ path = (key[0] == '.' and current_template) ? current_template.virtual_path.gsub('/', '.') + key : key
14
+ return ActiverecordI18n.get_item(path, default_value || key)
15
+ end
16
+
17
+ def self.get_item(key, default_value=nil)
18
+ translation = ActiverecordI18nTranslation.where(key: key.downcase, locale: I18n.locale).first_or_create()
19
+ if !translation.value
20
+ translation.value = (default_value || '').gsub('-', ' ')
21
+ translation.save
22
+ end
23
+ return translation.value
24
+ end
25
+ end
26
+
27
+ ActiveSupport.on_load(:action_view) do
28
+ include ActiverecordI18n::Helper
29
+ end
@@ -0,0 +1,22 @@
1
+ require "rails/generators/active_record"
2
+
3
+ module ActiverecordI18n
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include ActiveRecord::Generators::Migration
7
+ source_root File.join(__dir__, "templates")
8
+
9
+ def copy_migration
10
+ migration_template "migration.rb", "db/migrate/install_activerecord_i18n.rb", migration_version: migration_version
11
+ end
12
+
13
+ def generate_model
14
+ template "activerecord_i18n_translation.rb", "app/models/activerecord_i18n_translation.rb"
15
+ end
16
+
17
+ def migration_version
18
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ class ActiverecordI18nTranslation < ApplicationRecord
2
+ validates :key, uniqueness: {scope: [:locale]}
3
+ end
@@ -0,0 +1,17 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
+ def self.up
3
+ create_table :activerecord_i18n_translations do |t|
4
+ t.string :locale
5
+ t.string :key
6
+ t.text :value
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :activerecord_i18n_translations, :locale
11
+ add_index :activerecord_i18n_translations, :key
12
+ end
13
+
14
+ def self.down
15
+ drop_table :activerecord_i18n_translations
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Denis Fabien
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.3.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.3.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: 'A simple gem to add a translation mechanic to your existing apps '
48
+ email: denis.fabien.ca@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - MIT-LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - lib/activerecord_i18n.rb
57
+ - lib/activerecord_i18n/engine.rb
58
+ - lib/activerecord_i18n/helper.rb
59
+ - lib/activerecord_i18n/railtie.rb
60
+ - lib/activerecord_i18n/version.rb
61
+ - lib/generators/activerecord_i18n/install_generator.rb
62
+ - lib/generators/activerecord_i18n/templates/activerecord_i18n_translation.rb.tt
63
+ - lib/generators/activerecord_i18n/templates/migration.rb.tt
64
+ homepage: https://github.com/supernini/activerecord-i18n
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ allowed_push_host: https://rubygems.org
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.7.9
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A gem from translator ! Translation is writing in db not in file, additional
89
+ to the standard I18n.t
90
+ test_files: []