embedded_localization 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
data/README.textile
CHANGED
@@ -205,6 +205,9 @@ If your requirements are different, my approach might not work for you. In that
|
|
205
205
|
|
206
206
|
h2. Changes
|
207
207
|
|
208
|
+
h3. 0.2.4 (2012-03-02)
|
209
|
+
* Issue #5 : bugfix for attr_writer
|
210
|
+
|
208
211
|
h3. 0.2.3 (2012-03-02)
|
209
212
|
* Issue #4 : bugfix for attr_writer - no longer updates attributes if value didn't change => timestamps don't change in that case
|
210
213
|
|
@@ -2,9 +2,12 @@ module EmbeddedLocalization
|
|
2
2
|
module ActiveRecord
|
3
3
|
module InstanceMethods
|
4
4
|
|
5
|
-
# we only support fallbacks to I18n.default_locale for now
|
6
|
-
#
|
5
|
+
# - we only support fallbacks to I18n.default_locale for now
|
6
|
+
# - will convert given locale to symbol, e.g. "en","En" to :en
|
7
|
+
|
7
8
|
def get_localized_attribute(attr_name, locale)
|
9
|
+
locale = locale.downcase.to_sym if locale.class == String # ensure that locale is always a symbol
|
10
|
+
|
8
11
|
if self.i18n.has_key?(locale)
|
9
12
|
self.i18n[locale][attr_name]
|
10
13
|
else
|
@@ -16,7 +19,11 @@ module EmbeddedLocalization
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
22
|
+
# - will convert given locale to symbol, e.g. "en","En" to :en
|
23
|
+
|
19
24
|
def set_localized_attribute(attr_name, locale, new_translation)
|
25
|
+
locale = locale.downcase.to_sym if locale.class == String # ensure that locale is always a symbol
|
26
|
+
|
20
27
|
# first check if nothing changed - then we can just return, so that timestamps and other records don't get touched
|
21
28
|
if self.i18n.class == Hash && (self.i18n[I18n.locale]) && (self.i18n[I18n.locale][attr_name.to_sym] == new_translation)
|
22
29
|
return if (I18n.locale != I18n.default_locale)
|