Skip to content

Commit

Permalink
Merge pull request #1169 from kou/support-i18n-in-tag-text
Browse files Browse the repository at this point in the history
Support i18n in tag text
  • Loading branch information
lsegal committed May 28, 2018
2 parents d6491b4 + 682a209 commit 5d6986b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 5d6986b

Please sign in to comment.