Add a script to fetch all the current templates from a local fxa-content-server

This commit is contained in:
Andrew Chilton 2014-02-25 12:27:03 +13:00
Родитель 01a1097cca
Коммит dbdbed7840
2 изменённых файлов: 173 добавлений и 0 удалений

29
templates/README.md Normal file
Просмотреть файл

@ -0,0 +1,29 @@
# Templates #
To fetch all templates from the fxa-content-server.
See https://github.com/mozilla/fxa-auth-server/pull/567 for more info.
Firstly, add the languages found in `fetch-templates-from-content-server.js` to your
`server/config/local.json`.
Then start the fxa-content-server:
```
$ cd fxa-content-server
$ npm start
```
Back here, run this script:
```
$ node fetch-templates-from-content-server.js
```
Then add all of the `*.json` files to the repo. This is horrible, but it is temporary:
```
$ git add *.json
$ git commit -m 'Update all the initial localised templates'
```
(Ends)

Просмотреть файл

@ -0,0 +1,144 @@
var fs = require('fs')
var request = require('request')
var config = require('../config').root()
// now, fetch all of the templates we know about from the content server
console.log(config)
console.log(config.i18n.supportedLanguages)
// This list is from fxa-content-server/locale/* (minus README.md, templates/ and linux/)
//
// The reason we do this is because if we were to read our own config, it wouldn't
// be what is running in production and is actually used. Therefore, for now, we need
// to just get everything.
//
// So, when running fxa-content-server, you need to have all of these set up in
// the fxa-content-server/server/config/local.json.
var langs = [
'af',
'an',
'ar',
'as',
'ast',
'be',
'bg',
'bn-BD',
'bn-IN',
'br',
'bs',
'ca',
'cs',
'cy',
'da',
'de',
'el',
'en-GB',
'en-US',
'en-ZA',
'eo',
'es',
'es-AR',
'es-CL',
'es-ES',
'es-MX',
'et',
'eu',
'fa',
'ff',
'fi',
'fr',
'fy-NL',
'ga-IE',
'gd',
'gl',
'gu',
'gu-IN',
'he',
'hi-IN',
'hr',
'ht',
'hu',
'hy-AM',
'id',
'is',
'it',
'ja',
'ja-JP-mac',
'kk',
'km',
'kn',
'ko',
'ku',
'lij',
'lt',
'lv',
'mai',
'mk',
'ml',
'mr',
'ms',
'nb-NO',
'ne-NP',
'nl',
'nn-NO',
'or',
'osx',
'pa',
'pa-IN',
'pl',
'pt-BR',
'pt-PT',
'rm',
'ro',
'ru',
'si',
'sk',
'sl',
'son',
'sq',
'sr',
'sr-Cyrl',
'sr-Latn',
'sv-SE',
'ta',
'te',
'th',
'tr',
'uk',
'ur',
'vi',
'win32',
'xh',
'zh-CN',
'zh-TW',
'zu',
]
var types = [ 'verify', 'reset' ]
var remaining = langs.length
langs.forEach(function(lang) {
types.forEach(function(type) {
var opts = {
uri : config.contentServer.url + '/template/' + lang + '/' + type,
json : true,
}
request(opts, function(err, res, body) {
console.log('Fetched lang=%s, type=%s', lang, type)
console.log(body)
var filename = lang + '_' + type + '.json'
console.log('Saving %s', filename)
fs.writeFile(filename, JSON.stringify(body), function(err) {
if (err) return console.warn(err)
remaining -= 1
if ( remaining === 0 ) {
console.log('Done')
}
})
})
})
})