mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-09-29 05:36:48 +02:00
Add __ helper for common phrases
This commit is contained in:
parent
e605249f29
commit
510f9f19f4
5 changed files with 24 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
class @I18n
|
||||
default: 'en'
|
||||
constructor: (@langs = [@default]) ->
|
||||
constructor: (@langs = [@default], @phrases) ->
|
||||
|
||||
_: (obj, substitution) =>
|
||||
if typeof obj is 'object' or typeof obj is 'function'
|
||||
|
@ -8,14 +8,18 @@ class @I18n
|
|||
else
|
||||
obj
|
||||
|
||||
get_lang: (obj) ->
|
||||
__: (key) =>
|
||||
lang = @get_lang @phrases, (lang) => @phrases[lang]?[key]
|
||||
@phrases[lang]?[key] ? ''
|
||||
|
||||
get_lang: (obj, test = (lang) -> obj[lang]) ->
|
||||
for lang in @langs
|
||||
# eg. en-US
|
||||
return lang if obj[lang]
|
||||
return lang if test lang
|
||||
|
||||
lang = lang.replace /_\w+$/, ''
|
||||
# eg. en
|
||||
return lang if obj[lang]
|
||||
return lang if test lang
|
||||
|
||||
@default
|
||||
|
||||
|
@ -26,5 +30,13 @@ class @I18n
|
|||
str = str.replace("{#{key}}", substitution[key])
|
||||
str
|
||||
|
||||
@i18n = new I18n navigator.languages
|
||||
@i18n = new I18n navigator.languages,
|
||||
en:
|
||||
enable: "Enable"
|
||||
documentation: "Documentation"
|
||||
ja:
|
||||
enable: "有効"
|
||||
documentation: "ドキュメンテーション"
|
||||
|
||||
@_ = @i18n._
|
||||
@__ = @i18n.__
|
||||
|
|
|
@ -82,7 +82,7 @@ app.templates.notifUpdates = (docs, disabledDocs) ->
|
|||
for doc in disabledDocs
|
||||
html += "<li>#{doc.name}"
|
||||
html += " <code>→</code> #{doc.release}" if doc.release
|
||||
html += """<span class="_notif-info"><a href="/settings">Enable</a></span>"""
|
||||
html += """<span class="_notif-info"><a href="/settings">#{__ 'enable'}</a></span>"""
|
||||
html += '</ul></div>'
|
||||
|
||||
notif 'Updates', "#{html}</div>"
|
||||
|
|
|
@ -68,7 +68,7 @@ app.templates.aboutPage =
|
|||
<div class="_table">
|
||||
<table class="_credits">
|
||||
<tr>
|
||||
<th>Documentation
|
||||
<th>#{__ 'documentation'}
|
||||
<th>Copyright
|
||||
<th>License
|
||||
#{credit_table}
|
||||
|
@ -148,7 +148,7 @@ app.templates.aboutPage =
|
|||
<div class="_table">
|
||||
<table class="_credits">
|
||||
<tr>
|
||||
<th>Documentation
|
||||
<th>#{__ 'documentation'}
|
||||
<th>Copyright
|
||||
<th>License
|
||||
#{credit_table}
|
||||
|
|
|
@ -13,7 +13,7 @@ app.templates.offlinePage = (docs) -> """
|
|||
<div class="_table">
|
||||
<table class="_docs">
|
||||
<tr>
|
||||
<th>Documentation</th>
|
||||
<th>#{__ 'documentation'}</th>
|
||||
<th class="_docs-size">Size</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
|
|
|
@ -7,7 +7,7 @@ templates.sidebarDoc = (doc, options = {}) ->
|
|||
link += if options.disabled then '_list-disabled' else '_list-dir'
|
||||
link += """" data-slug="#{doc.slug}" title="#{doc.fullName}" tabindex="-1">"""
|
||||
if options.disabled
|
||||
link += """<span class="_list-enable" data-enable="#{doc.slug}">Enable</span>"""
|
||||
link += """<span class="_list-enable" data-enable="#{doc.slug}">#{__ 'enable'}</span>"""
|
||||
else
|
||||
link += arrow
|
||||
link += """<span class="_list-count">#{doc.release}</span>""" if doc.release
|
||||
|
@ -23,7 +23,7 @@ templates.sidebarEntry = (entry) ->
|
|||
|
||||
templates.sidebarResult = (entry) ->
|
||||
addons = if entry.isIndex() and app.disabledDocs.contains(entry.doc)
|
||||
"""<span class="_list-enable" data-enable="#{entry.doc.slug}">#{_ en: "Enable", ja: "有効"}</span>"""
|
||||
"""<span class="_list-enable" data-enable="#{entry.doc.slug}">#{__ 'enable'}</span>"""
|
||||
else
|
||||
"""<span class="_list-reveal" data-reset-list title="Reveal in list"></span>"""
|
||||
addons += """<span class="_list-count">#{entry.doc.short_version}</span>""" if entry.doc.version and not entry.isIndex()
|
||||
|
@ -66,9 +66,7 @@ templates.sidebarDisabledList = (html) ->
|
|||
templates.sidebarDisabledVersionedDoc = (doc, versions) ->
|
||||
"""<a class="_list-item _list-dir _icon-#{doc.icon} _list-disabled" data-slug="#{doc.slug_without_version}" tabindex="-1">#{arrow}#{doc.name}</a><div class="_list _list-sub">#{versions}</div>"""
|
||||
|
||||
templates.docPickerHeader =
|
||||
en: """<div class="_list-picker-head"><span>Documentation</span> <span>Enable</span></div>"""
|
||||
ja: """<div class="_list-picker-head"><span>ドキュメント</span> <span>Enable</span></div>"""
|
||||
templates.docPickerHeader = -> """<div class="_list-picker-head"><span>#{__ 'documentation'}</span> <span>#{__ 'enable'}</span></div>"""
|
||||
|
||||
templates.docPickerNote =
|
||||
en: """
|
||||
|
|
Loading…
Reference in a new issue