Skip to content

Commit 67dc3d4

Browse files
committed
Automated more of getting locale files from Twitter
1 parent d156f61 commit 67dc3d4

7 files changed

Lines changed: 37 additions & 101 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules/
44
promo/*.png
55
!promo/blue_promo.png
66
scripts/locales/html/*.html
7+
scripts/locales/js/_files.txt
78
scripts/locales/js/*.js
89
scripts/locales/locales.js
910
web-ext-artifacts/

scripts/locales/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
## Updating Locales
22

3-
Tweak `html/_files.txt` if needed to add new locales.
3+
### Get locale files from Twitter
44

5-
In `html/` run `curl -K _files.txt` to retrieve HTML from Twitter with the latest URLs for hashed locale files.
5+
> Tweak `html/_files.txt` and `create-js-curl-config.js` first if locales have changed.
66
7-
Use the contents of the HTML files to update `js/_files.txt` - left as an exercise for the reader.
7+
```sh
8+
(cd html && curl -K _files.txt)
9+
node create-js-curl-config.js
10+
(cd js && curl -K _files.txt)
11+
```
812

9-
In `js/` run `curl -K _files.txt` to retrieve locale files.
13+
### Create locale object for tweak-new-twitter.user.js
1014

11-
Run `node create-locales.js` to create a `locales.js` file and use it to update `tweak-new-twitter.user.js`.
15+
Run `node create-locales.js` to create `locales.js`.
16+
17+
Open it, save to format it with Prettier, then use its contents to update `tweak-new-twitter.user.js`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
let curlConfig = ''
5+
for (let file of fs.readdirSync('./html')) {
6+
if (!file.endsWith('.html')) continue
7+
let localeCode = file.split('.')[0]
8+
let html = fs.readFileSync(path.join('html', file), {encoding: 'utf8'})
9+
let match = html.match(
10+
new RegExp(
11+
`https://abs\\.twimg\\.com/responsive-web/client-web-legacy/i18n/${localeCode}\\.(?:[a-z\\d]+)\\.js`
12+
)
13+
)
14+
15+
if (!match) {
16+
console.log('could not find locale file URL', {file, localeCode})
17+
continue
18+
}
19+
20+
curlConfig += `-o ${localeCode}.js\nurl="${match[0]}"\n`
21+
}
22+
23+
fs.writeFileSync('./js/_files.txt', curlConfig)

scripts/locales/create-locales.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,6 @@ for (let file of fs.readdirSync('./js')) {
231231
locales[localeCode] = sortProperties(locale)
232232
}
233233

234-
fs.writeFileSync('locales.js', JSON.stringify(locales, null, 2), {
234+
fs.writeFileSync('locales.js', 'let locales = ' + JSON.stringify(locales, null, 2), {
235235
encoding: 'utf8',
236236
})

scripts/locales/js/.gitkeep

Whitespace-only changes.

scripts/locales/js/_files.txt

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

tweak-new-twitter.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ const locales = {
651651
uk: {
652652
ADD_MUTED_WORD: 'Додати слово до списку ігнорування',
653653
DISCOVER_MORE: 'Дізнавайтеся більше',
654-
FOLLOWING: 'Читає(те)',
654+
FOLLOWING: 'Стрічка',
655655
HOME: 'Головна',
656656
MUTE_THIS_CONVERSATION: 'Ігнорувати цю розмову',
657657
QUOTE_TWEET: 'Цитувати твіт',

0 commit comments

Comments
 (0)