Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Add Lita.default_locale=.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Sep 25, 2020
1 parent 20be99f commit 8f669f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/lita/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@ def load_locales(paths)
I18n.reload!
end

# Sets I18n.locale, normalizing the provided locale name.
# Sets +I18n.locale+, normalizing the provided locale name.
#
# Note that setting this only affects the current thread. Since handler
# methods are dispatched in new threads, changing the locale globally will
# require calling this method at the start of every handler method.
# Alternatively, use {Lita#default_locale=} which will affect all threads.
# @param new_locale [Symbol, String] The code of the locale to use.
# @return [void]
# @since 3.0.0
def locale=(new_locale)
I18n.locale = new_locale.to_s.tr("_", "-")
end

# Sets +I18n.default_locale+, normalizing the provided locale name.
#
# This is preferred over {Lita#locale=} as it affects all threads.
# @param new_locale [Symbol, String] The code of the locale to use.
# @return [void]
# @since 4.8.0
def default_locale=(new_locale)
I18n.default_locale = new_locale.to_s.tr("_", "-")
end

# The absolute path to Lita's templates directory.
# @return [String] The path.
# @since 3.0.0
Expand Down
7 changes: 7 additions & 0 deletions spec/lita_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
end
end

describe ".default_locale=" do
it "sets I18n.default_locale to the normalized locale" do
expect(I18n).to receive(:default_locale=).with("zh-TW")
described_class.default_locale = "zh_TW"
end
end

describe ".redis" do
let(:redis_namespace) { instance_double("Redis") }

Expand Down

0 comments on commit 8f669f0

Please sign in to comment.