Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…g all this.
- Loading branch information
Showing
4 changed files
with
65 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# NOTE: this will soon be moved to cells-rails. | ||
module Cell::Translation | ||
def self.included(includer) | ||
super | ||
includer.inheritable_attr :translation_path | ||
end | ||
|
||
def initialize(*) | ||
super | ||
@virtual_path = translation_path | ||
end | ||
|
||
private | ||
# If you override this to change this path, please report it on the trailblazer/chat gitter channel, | ||
# so we can find out best practices. | ||
def translation_path | ||
self.class.translation_path or controller_path.gsub("/", ".") | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "test_helper" | ||
require "cells/translation" | ||
|
||
class TranslationTest < MiniTest::Spec | ||
class I18nCell < Cell::ViewModel | ||
include ActionView::Helpers::TranslationHelper | ||
include Translation | ||
|
||
def greet_relative | ||
t(".greeting") # gets appended to translation_test.i18n. | ||
end | ||
|
||
def greet_absolute | ||
t("translation_test.i18n.greeting") | ||
end | ||
end | ||
|
||
I18n.backend = I18n::Backend::KeyValue.new({}) | ||
I18n.backend.store_translations(:en, | ||
{ "translation_test.i18n.greeting" => "Translated!", | ||
"cell.friendly.greeting" => "Hello you!" }, | ||
escape: false) | ||
|
||
# Translate text specified by an absolute path | ||
it { I18nCell.new.greet_absolute.must_equal "Translated!" } | ||
|
||
# Translate text specified by an relative path | ||
it { I18nCell.new.greet_relative.must_equal "Translated!" } | ||
|
||
|
||
describe "::translation_path" do | ||
class ExplicitI18NCell < Cell::ViewModel | ||
include ActionView::Helpers::TranslationHelper | ||
include Translation | ||
|
||
self.translation_path = "cell.friendly" | ||
|
||
def show | ||
t(".greeting") | ||
end | ||
end | ||
|
||
it { ExplicitI18NCell.new.().must_equal "Hello you!" } | ||
end | ||
end |