Skip to content

Commit a781686

Browse files
committed
fixup! fixup! fixup! DONOTMERGE!!!!! Revert "Allow changing language from dropdown, only build base, create script for html-translations."
This reverts commit b115ab0.
1 parent b0882f9 commit a781686

File tree

10 files changed

+85
-110
lines changed

10 files changed

+85
-110
lines changed

lib/build-challenges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var layout = fs.readFileSync(path.normalize(path.join(__dirname, '../resources/l
1414
var files = []
1515

1616
// Take in a language type if any
17-
var langs = ['en-US'] // TODO Adapt - Only short Term fix here
17+
var langs = locale.getAvaiableLocales()
1818
var input = ''
1919
var output = ''
2020

lib/build-pages.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ var path = require('path')
88
var locale = require('./locale.js')
99
var Handlebars = require('handlebars')
1010

11-
// TODO Adapt - Only short Term fix here
12-
var langs = ['en-US']
11+
var langs = locale.getAvaiableLocales()
1312

1413
var layout = fs.readFileSync(path.normalize(path.join(__dirname, '..', 'resources', 'layouts', 'page.hbs'))).toString()
1514
var input = ''

lib/i18n-translate.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

lib/languages.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Touches the DOM.
3+
// This file listens to events from the language selector and changes the
4+
// DOM to have the language requested.
5+
// Uses globals from chal-header.html.
6+
//
7+
8+
// Selecting the current locale
9+
var selector = document.getElementById('lang-select')
10+
11+
// add change listener
12+
selector.addEventListener('change', function (event) {
13+
// Go to page in the locale specified
14+
var location = window.location
15+
var url = location.href.replace(/built\/([a-z]{2}-[A-Z]{2})/, 'built/' + selector.value)
16+
location.href = url
17+
})

lib/locale.js

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var path = require('path')
2-
const { appLanguages } = require('../config/i18next.config')
32

43
/**
54
* available
@@ -8,7 +7,15 @@ const { appLanguages } = require('../config/i18next.config')
87
* @type {string[]}
98
*/
109
var available = {
11-
'en-US': 'English'
10+
'en-US': 'English',
11+
'ja-JP': '日本語',
12+
'zh-TW': '中文(臺灣)',
13+
'ko-KR': '한국어',
14+
'pt-BR': 'Português Brasileiro',
15+
'uk-UA': 'Українська',
16+
'es-CO': 'Español (Colombia)',
17+
'es-ES': 'Español (España)',
18+
'fr-FR': 'Français'
1219
}
1320

1421
/**
@@ -17,7 +24,14 @@ var available = {
1724
* @type {string[]}
1825
*/
1926
var aliases = {
20-
en: 'en-US'
27+
en: 'en-US',
28+
ja: 'ja-JP',
29+
zh: 'zh-TW',
30+
kr: 'ko-KR',
31+
br: 'pt-BR',
32+
uk: 'uk-UA',
33+
es: 'es-ES',
34+
fr: 'fr-FR'
2135
}
2236

2337
/**
@@ -108,6 +122,29 @@ function getLocaleResourcesPath (lang) {
108122
return path.join(basepath, 'resources', 'contents', getLocale(lang))
109123
}
110124

125+
/**
126+
* Get the locale name.
127+
* @param lang
128+
* @return {string}
129+
*/
130+
function getLocaleName (lang) {
131+
if (isAvaliable(lang)) {
132+
return available[lang]
133+
} else if (isAlias(lang)) {
134+
return available[getAliasLocale(lang)]
135+
} else {
136+
throw new Error('locale ' + lang + ' do not exist.Do you add it in lib/locale.js?')
137+
}
138+
}
139+
140+
/**
141+
* Get the avaiable locale array.
142+
* @return {Array}
143+
*/
144+
function getAvaiableLocales () {
145+
return Object.keys(available)
146+
}
147+
111148
/**
112149
* Get fallback.
113150
* @type {string}
@@ -121,17 +158,22 @@ function getFallbackLocale () {
121158
* @return {string}
122159
*/
123160
function getLocaleMenu (current) {
124-
let menu = ''
125-
Object.entries(appLanguages).forEach(([languageKey, language]) => {
126-
menu = menu.concat('<option value="' + languageKey + '">' + language + '</option>')
127-
})
128-
161+
var menu = ''
162+
for (var lang in available) {
163+
if (lang === current) {
164+
menu = menu.concat('<option value="' + lang + '" selected="selected">' + getLocaleName(lang) + '</option>')
165+
} else {
166+
menu = menu.concat('<option value="' + lang + '">' + getLocaleName(lang) + '</option>')
167+
}
168+
}
129169
return menu
130170
}
131171

132172
module.exports.getLocale = getLocale
133173
module.exports.getLocaleBuiltPath = getLocaleBuiltPath
134174
module.exports.getLocaleResourcesPath = getLocaleResourcesPath
135175
module.exports.getCurrentLocale = getCurrentLocale
176+
module.exports.getLocaleName = getLocaleName
177+
module.exports.getAvaiableLocales = getAvaiableLocales
136178
module.exports.getFallbackLocale = getFallbackLocale
137179
module.exports.getLocaleMenu = getLocaleMenu

main.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ app.on('ready', function appReady () {
8484
})
8585
}
8686
})
87-
88-
buildMenus()
8987
mainWindow.loadURL('file://' + locale.getLocaleBuiltPath(language) + '/pages/index.html')
9088

91-
/*
92-
* Create ipc listeners
93-
*/
9489
ipcMain.on('getUserDataPath', function (event) {
9590
event.returnValue = userDataPath
9691
})
@@ -118,30 +113,18 @@ app.on('ready', function appReady () {
118113
event.sender.send('confirm-clear-response', resp)
119114
})
120115

121-
/*
122-
* Create i18n Listener
123-
*/
124-
global.i18n.on('languageChanged', () => {
125-
buildMenus()
126-
})
127-
128-
/*
129-
* MainWindow Listener
130-
*/
131-
mainWindow.on('closed', function winClosed () {
132-
mainWindow = null
133-
})
134-
})
135-
136-
function buildMenus () {
137116
if (process.platform === 'darwin') {
138117
menu = Menu.buildFromTemplate(darwinTemplate(app, mainWindow, global.i18n))
139118
Menu.setApplicationMenu(menu)
140119
} else {
141120
menu = Menu.buildFromTemplate(otherTemplate(app, mainWindow, global.i18n))
142121
mainWindow.setMenu(menu)
143122
}
144-
}
123+
124+
mainWindow.on('closed', function winClosed () {
125+
mainWindow = null
126+
})
127+
})
145128

146129
function setAllChallengesComplete (path) {
147130
var challenges = JSON.parse(fs.readFileSync(path))

resources/contents/en-US/pages/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<link rel="stylesheet" href="../../../assets/css/buttons.css">
99
<link rel="stylesheet" href="../../../assets/octicons.css">
1010
<script src="../../../lib/challenges-completed.js"></script>
11+
<script src="../../../lib/handle-external-links.js"></script>
1112
</head>
1213
<body class="index-page">
1314
<header class="site-header">
@@ -113,7 +114,6 @@ <h1 i18n-data="index~Congratulations!"></h1>
113114
</div>
114115

115116
</div>
116-
<script src="../../../lib/i18n-translate.js"></script>
117-
<script src="../../../lib/handle-external-links.js"></script>
117+
<script src="../../../lib/languages.js"></script>
118118
</body>
119119
</html>

resources/contents/en-US/partials/header.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
</a>
1010
<span class="challenge-title">{{ pageTitle }}</span>
1111
</header>
12+
13+
14+
<script>
15+
var selector = document.getElementById('lang-select');
16+
selector.value = "{{ lang }}"
17+
</script>

resources/layouts/challenge.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
challengeStatus.completed(currentChallenge)
2727
</script>
2828

29-
<script>require('../../../lib/challenge.js')</script>
30-
<script>require('../../../lib/i18n-translate.js')</script>
3129
<script>require('../../../lib/handle-external-links.js')</script>
30+
<script>require('../../../lib/languages.js')</script>
31+
<script>require('../../../lib/challenge.js')</script>
3232
</body>
3333
</html>

resources/layouts/page.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<link rel="stylesheet" href="../../../assets/css/new-style.css">
77
<link rel="stylesheet" href="../../../assets/css/new-challenge.css">
88
<link rel="stylesheet" href="../../../assets/css/buttons.css">
9+
<script>require('../../../lib/handle-external-links.js')</script>
910
</head>
1011

1112
<body>
@@ -15,7 +16,5 @@
1516
{{{ body }}}
1617
</div>
1718

18-
<script src="../../../lib/i18n-translate.js"></script>
19-
<script>require('../../../lib/handle-external-links.js')</script>
2019
</body>
2120
</html>

0 commit comments

Comments
 (0)