Skip to content

Commit

Permalink
Merge pull request #890 from kmuto/chapterdisplay
Browse files Browse the repository at this point in the history
chapref, columnの参照文字列のgettext化の改善
  • Loading branch information
kmuto authored Aug 30, 2018
2 parents f3ff466 + 261abdf commit 144ab5d
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
6 changes: 5 additions & 1 deletion lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def title(id)
end

def display_string(id)
"#{number(id)}#{I18n.t('chapter_quote', title(id))}"
if number(id)
I18n.t('chapter_quote', [number(id), title(id)])
else
I18n.t('chapter_quote_without_number', title(id))
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def inline_column(id)
end

def inline_column_chap(chapter, id)
chapter.column(id).caption
I18n.t('column', chapter.column(id).caption)
end

def inline_pageref(id)
Expand Down
4 changes: 2 additions & 2 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ def inline_bib(id)
def inline_hd_chap(chap, id)
n = chap.headline_index.number(id)
if chap.number and @book.config['secnolevel'] >= n.split('.').size
str = I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
str = I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
else
str = I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
end
if @book.config['chapterlink']
anchor = 'h' + n.gsub('.', '-')
Expand Down
6 changes: 6 additions & 0 deletions lib/review/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def update_localefile(path)
@store[key].merge!(values)
end
end

# check obsolete locale parameter
s = t('chapter_quote', ['__!@!NUMBER!@!__', '__!@!TITLE!@!__'])
if s !~ /__!@!NUMBER!@!__/ || s !~ /__!@!TITLE!@!__/
ReVIEW.logger.warn %Q('chapter_quote' should take 2 '%s' (number and title).)
end
end

def update(user_i18n, locale = nil)
Expand Down
18 changes: 15 additions & 3 deletions lib/review/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ ja:
chapter: 第%d章
chapter_short: "%d"
chapter_postfix: " "
chapter_quote: "「%s」"
chapter_quote: "%s「%s」"
chapter_quote_without_number: "「%s」"
hd_quote: "「%s %s」"
hd_quote_without_number: "「%s」"
appendix: 付録%pA
numberless_image: "図:"
memo_head: ■メモ
Expand Down Expand Up @@ -72,7 +75,10 @@ en:
chapter: Chapter %d
chapter_short: "%d"
chapter_postfix: ". "
chapter_quote: '"%s"'
chapter_quote: '%s "%s"'
chapter_quote_without_number: '"%s"'
hd_quote: '"%s %s"'
hd_quote_without_number: '"%s"'
appendix: Appendix %s
numberless_image: "Figure:"
memo_head: Note
Expand Down Expand Up @@ -126,12 +132,18 @@ zh-TW:
image:
table:
list: List
column: "Column %s"
columnname: "Column"
column_head: "Column"
part: 第%pR部份
part_short: "%pR"
chapter: 第%d章
chapter_short: "%d"
chapter_postfix: " "
chapter_quote: "「%s」"
chapter_quote: "%s「%s」"
chapter_quote_without_number: "「%s」"
hd_quote: "「%s %s」"
hd_quote_without_number: "「%s」"
appendix: 附錄%s
numberless_image: "圖:"
format_number: "%s.%d"
Expand Down
4 changes: 2 additions & 2 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,10 @@ def inline_hd_chap(chap, id)
if chap.number
n = chap.headline_index.number(id)
if @book.config['secnolevel'] >= n.split('.').size
return I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
return I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
end
end
I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
rescue KeyError
error "unknown headline: #{id}"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,9 @@ def inline_bib(id)
def inline_hd_chap(chap, id)
n = chap.headline_index.number(id)
if chap.number and @book.config['secnolevel'] >= n.split('.').size
str = I18n.t('chapter_quote', "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
str = I18n.t('hd_quote', [chap.headline_index.number(id), compile_inline(chap.headline(id).caption)])
else
str = I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
end
if @book.config['chapterlink']
anchor = n.gsub(/\./, '-')
Expand All @@ -1006,7 +1006,7 @@ def inline_hd_chap(chap, id)

def inline_column_chap(chapter, id)
macro('reviewcolumnref',
I18n.t('chapter_quote', compile_inline(chapter.column(id).caption)),
I18n.t('column', compile_inline(chapter.column(id).caption)),
column_label(id, chapter))
rescue KeyError
error "unknown column: #{id}"
Expand Down
4 changes: 2 additions & 2 deletions lib/review/plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ def inline_hd_chap(chap, id)
if chap.number
n = chap.headline_index.number(id)
if @book.config['secnolevel'] >= n.split('.').size
return I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
return I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
end
end
I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
rescue KeyError
error "unknown headline: #{id}"
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def test_column_ref
inside column
next level
this is test.
this is コラム「test.
EOS

assert_equal expected, column_helper(review)
Expand Down
2 changes: 1 addition & 1 deletion test/test_rstbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_column_ref
next level
--------------------
this is test.
this is コラム「test.
EOS

Expand Down
2 changes: 1 addition & 1 deletion test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def test_column_ref
◆→終了:コラム←◆
■H3■next level
this is test.
this is コラム「test.
EOS

assert_equal expected, column_helper(review)
Expand Down

0 comments on commit 144ab5d

Please sign in to comment.