Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support i18n in tag text #1169

Merged
merged 1 commit into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/yard/code_objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,15 @@ def translate_docstring(locale)
text = I18n::Text.new(@docstring)
localized_text = text.translate(locale)
docstring = Docstring.new(localized_text, self)
docstring.add_tag(*@docstring.tags)
@docstring.tags.each do |tag|
if tag.is_a?(Tags::Tag)
localized_tag = tag.clone
localized_tag.text = I18n::Text.new(tag.text).translate(locale)
docstring.add_tag(localized_tag)
else
docstring.add_tag(tag)
end
end
docstring
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/code_objects/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ class X; end
expect(o.docstring('fr')).to eq "Bonjour"
end

it "returns localized docstring tag" do
o = CodeObjects::MethodObject.new(:root, 'Hello#message')
o.docstring.add_tag(Tags::Tag.new('return', 'Hello'))

fr_locale = YARD::I18n::Locale.new('fr')
allow(fr_locale).to receive(:translate).with('Hello').and_return('Bonjour')
allow(Registry).to receive(:locale).with('fr').and_return(fr_locale)

expect(o.docstring('fr').tags.map(&:text)).to eq ['Bonjour']
end

it "returns updated localized docstring" do
fr_locale = YARD::I18n::Locale.new('fr')
allow(Registry).to receive(:locale).with('fr').and_return(fr_locale)
Expand Down