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

Proof-of-concept for i18n support #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions assets/i18next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
i18next
.use(i18nextXHRBackend)
.use(i18nextBrowserLanguageDetector)
.init({
fallbackLng: 'zh',
whitelist: ['en', 'zh'],
debug: true,
backend: {
loadPath: 'https://gist.githubusercontent.com/patcon/1f68d3efd30360048bce81b3a7655c5b/raw/{{lng}}.json',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should def point somewhere else, and prob to a raw file on github repo, or a json file hosted as part of app

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think it's better to also include these two json files in the PR

crossDomain: true
}
}, function(err, t) {
translations = [
'x-expand',
'x-collapse',
'x-recent',
'x-zoom',
'x-help',
'add',
'edit',
'update'
]
translations.forEach(function (key) {
if (key.startsWith('x-')) {
key = key.substring(2)
document.getElementById('desktop-'+key).setAttribute("data-content", i18next.t('index.'+key))
document.getElementById('mobile-'+key).setAttribute("data-content", i18next.t('index.'+key))
} else {
document.getElementById(key).setAttribute("data-content", i18next.t('index.'+key))
}
});
document.querySelector('[for=add-only]').innerHTML = i18next.t('index.add-link');
document.querySelector('[for=create-add]').innerHTML = i18next.t('index.create-add-hackpad');
document.querySelector('[name=new-link-title]').setAttribute('placeholder', i18next.t('index.link-name'));
document.querySelector('[name=new-link-url]').setAttribute('placeholder', i18next.t('index.link-url'));
document.querySelector('[name=new-pad-name]').setAttribute('placeholder', i18next.t('index.hackpad-name'));
});
6 changes: 6 additions & 0 deletions views/_template.jade
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ html
link(rel="stylesheet",type="text/css",href="/assets/semantic-ui/0.19.0/css/semantic.min.css")
script(type="text/javascript",src="/assets/semantic-ui/0.19.0/javascript/semantic.min.js")

// i18next
script(src="//unpkg.com/i18next/i18next.js")
script(src="//unpkg.com/i18next-xhr-backend/i18nextXHRBackend.js")
script(src="//unpkg.com/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.js")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to pull these from a CDN?

script(type="text/javascript",src="/assets/i18next.js")


//-meta(http-equiv="X-UA-Compatible",content="IE=edge")
//-meta(name="description",content="")
Expand Down
26 changes: 13 additions & 13 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ block body
.ui.borderless.menu
include white_label-shortcuts-nav
.ui.dropdown.icon.item.history
i.icon.time
i.icon.time(id="desktop-recent")
include foldr_history-menu
.ui.dropdown.icon.item.about
i.icon.help
i.icon.help(id="desktop-help")
include help-menu
a.right.item.expand.button.collapsed.mode.hidden.desktop.only
i.icon.arrow.right(data-content="展開")
i.icon.arrow.right(id="desktop-expand", data-content="展開")
a.right.item.collapse.button.expanded.mode.desktop.only
i.icon.arrow.left(data-content="收合")
i.icon.arrow.left(id="desktop-collapse", data-content="收合")
.right.icon.item.zoom.ui.dropdown
i.icon.zoom.in
i.icon.zoom.in(id="desktop-zoom")
include zoom-menu

//- on mobile / tablet / phone, nav bar content is merged into this bar
Expand All @@ -31,15 +31,15 @@ block body
span.text
include white_label-shortcuts-topbar
.ui.dropdown.icon.item.history.tablet.only
i.icon.time
i.icon.time(id="mobile-recent")
include foldr_history-menu
.ui.dropdown.icon.item.about.tablet.only
i.icon.help
i.icon.help(id="mobile-help")
include help-menu
a.right.item.show.nav.button.collapsed.mode.mobile.only
i.icon.arrow.down(data-content="展開")
i.icon.arrow.down(id="mobile-expand", data-content="展開")
a.right.item.hide.nav.button.expanded.mode.hidden.mobile.only
i.icon.arrow.up(data-content="收合")
i.icon.arrow.up(id="mobile-collapse", data-content="收合")
.right.ui.dropdown.icon.item.meta.phone.only
i.icon.ellipsis.vertical
.menu
Expand All @@ -55,14 +55,14 @@ block body
i.icon.help
include help-menu
.right.icon.item.zoom.ui.dropdown.tablet.only
i.icon.zoom.in
i.icon.zoom.in(id="mobile-zoom")
include zoom-menu
a.right.icon.item.edit.table(target="iframe")
i.icon.pencil(data-content="編輯")
i.icon.pencil(id="edit", data-content="編輯")
a.right.icon.item.refresh.table.hidden
i.icon.repeat(data-content="更新")
i.icon.repeat(id="update", data-content="更新")
a.right.icon.item.add.to.list.hidden
i.icon.add
i.icon.add(id="add")
.ui.segment.submit.no.margin.hidden.expanded.mode
.ui.form
.inline.field
Expand Down