activerecord-mlang 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/mlang.rb +4 -10
- data/lib/active_record/mlang/lang.rb +6 -2
- data/lib/activerecord/mlang/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6d876dfc4e28efbff05f9aca3a14d3cbc650bbd
|
4
|
+
data.tar.gz: cb092b2200010930203be266e1f07fdf0db32b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7ecb212e4db96e99f1f96ef4fb479a848d53a72bd3dcf2f52f6250945472e4ab05a080db6597e24dce8faa28679297b32d13770bdf5af9ca124f593f55492a
|
7
|
+
data.tar.gz: fdebe50f6d39be6e9f49610dc5420d28676e437969444f7b336a2dd89244b246d444c56741b3231f915178d1df617a13a447bd7cd4514687c95a9647702a2297
|
data/lib/active_record/mlang.rb
CHANGED
@@ -51,19 +51,13 @@ module ActiveRecord
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def text(
|
54
|
+
def text(locale_or_lang_id=nil)
|
55
55
|
return nil if !self.persisted?
|
56
|
-
local_or_lang_id ||= I18n.locale || I18n.default_locale
|
57
|
-
lang_id = nil
|
58
|
-
if local_or_lang_id.kind_of? Integer
|
59
|
-
lang_id = local_or_lang_id if Lang.exists?(id: local_or_lang_id)
|
60
|
-
else
|
61
|
-
lang_id = Lang[local_or_lang_id].try(:id)
|
62
|
-
end
|
63
56
|
|
64
|
-
|
57
|
+
locale_or_lang_id ||= I18n.locale || I18n.default_locale
|
58
|
+
return nil if !(lang = Lang[locale_or_lang_id])
|
65
59
|
|
66
|
-
texts.find_or_create_by(lang_id:
|
60
|
+
texts.find_or_create_by(lang_id: lang.id)
|
67
61
|
end
|
68
62
|
end
|
69
63
|
end
|
@@ -3,8 +3,12 @@ module ActiveRecord
|
|
3
3
|
module Mlang
|
4
4
|
class Lang < ActiveRecord::Base
|
5
5
|
include ActiveRecord::Mlang
|
6
|
-
def self.[]
|
7
|
-
|
6
|
+
def self.[] locale_or_lang_id
|
7
|
+
if locale_or_lang_id.kind_of? Integer
|
8
|
+
self.find_by(id: locale_or_lang_id)
|
9
|
+
else
|
10
|
+
self.find_by(code: locale_or_lang_id)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mlang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinjiro Itagaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|