From ae471187281a14ed8f0ca46e659c4fe14456d3a4 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Fri, 21 Sep 2018 10:47:38 +0800 Subject: [PATCH] * Expose translations with option to perform initalization --- lib/i18n/backend/simple.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/i18n/backend/simple.rb b/lib/i18n/backend/simple.rb index 48aeaf48..231116c1 100644 --- a/lib/i18n/backend/simple.rb +++ b/lib/i18n/backend/simple.rb @@ -59,6 +59,14 @@ def reload! super end + def translations(do_init: false) + # To avoid returning empty translations, + # call `init_translations` + init_translations if do_init && !initialized? + + @translations ||= {} + end + protected def init_translations @@ -66,10 +74,6 @@ def init_translations @initialized = true end - def translations - @translations ||= {} - end - # Looks up a translation from the translations hash. Returns nil if # either key is nil, or locale, scope or key do not exist as a key in the # nested translations hash. Splits keys or scopes containing dots