Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from lynnfaraday/en.yml
Last active November 9, 2016 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radar/c74cadff6dee7988f764536d667f44df to your computer and use it in GitHub Desktop.
Save radar/c74cadff6dee7988f764536d667f44df to your computer and use it in GitHub Desktop.
Illustrating i18n issue
en:
hello: "Hello world"
source 'https://rubygems.org'
gem "pry"
gem 'i18n', github: "svenfuchs/i18n", branch: "173-reset-load-path"
gem "rspec"
GIT
remote: git://github.com/svenfuchs/i18n.git
revision: e711e7921e58637ba03ebeb8990285c415c4c0b5
branch: 173-reset-load-path
specs:
i18n (0.7.0)
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.1)
diff-lcs (1.2.5)
method_source (0.8.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
slop (3.6.0)
PLATFORMS
ruby
DEPENDENCIES
i18n!
pry
rspec
BUNDLED WITH
1.13.5
require 'rspec'
require 'i18n'
describe "I18n" do
it "should translate hello to english" do
I18n.load_path << Dir.pwd + "/en.yml"
puts "Translate English"
I18n.locale = :en
expect(I18n.t("hello")).to eq "Hello world"
end
it "should fail if a translation is not found" do
puts "Translation fail"
expect(I18n.t('test')).to eq "translation missing: en.test"
end
end
require 'rspec'
require 'i18n'
describe "I18n" do
it "should fail if a translation is not found" do
puts "Translation fail"
expect {I18n.t('test') }.to raise_error(I18n::InvalidLocale)
end
it "should translate hello to english" do
I18n.load_path += [Dir.pwd + "/en.yml"]
puts "Translate English"
I18n.locale = :en
expect(I18n.t("hello")).to eq "Hello world"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment