Skip to content

Commit

Permalink
Merge pull request #353 from PikachuEXE/feature/change-translations-b…
Browse files Browse the repository at this point in the history
…ehaviour

Expose `translations` in simple backend and load translations only when not loaded
  • Loading branch information
radar authored Sep 23, 2018
2 parents 9aa9a91 + ae47118 commit c75cd40
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/i18n/backend/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ 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
load_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
Expand Down

0 comments on commit c75cd40

Please sign in to comment.