Skip to content

Commit

Permalink
Expose #translate instead of #store in the main module
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 19, 2024
1 parent ef6d3b9 commit e6a62fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rosetta-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def locale_session
Thread.current[:rosetta_locale_session] ||= LocaleSession.new
end

def store
Store.for_locale(Rosetta.locale)
def translate(key, locale: Rosetta.locale)
store = Store.for_locale(locale)
store.lookup(key)
end

def config
Expand Down
6 changes: 6 additions & 0 deletions test/rosetta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class RosettaTest < ActiveSupport::TestCase
assert_equal Rosetta.locale, Rosetta::Locale.default_locale
end

test "#translate translates the key in the selected loacle" do
Rosetta.with_locale(rosetta_locales(:french)) { assert_equal "bonjour", Rosetta.translate("hello") }
assert_equal "bonjour", Rosetta.translate("hello", locale: rosetta_locales(:french))
assert_equal "hola", Rosetta.translate("hello", locale: rosetta_locales(:spanish))
end

test "configuring the default locale" do
Rosetta.configure { |config| config.set_default_locale(name: "French", code: "fr") }
assert_equal "French", Rosetta.config.default_locale.name
Expand Down

0 comments on commit e6a62fb

Please sign in to comment.