Skip to content

Commit

Permalink
enh: Move package to vite for bundling + compress translations
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jan 9, 2024
1 parent cac60e3 commit d0a6ca7
Show file tree
Hide file tree
Showing 15 changed files with 4,518 additions and 15,053 deletions.
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions build/extract-l10n.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GettextExtractor, JsExtractors } = require('gettext-extractor')
import { GettextExtractor, JsExtractors } from 'gettext-extractor'

const extractor = new GettextExtractor()
const extractor = new GettextExtractor();

extractor
.createJsParser([
Expand All @@ -11,7 +11,7 @@ extractor
},
}),
])
.parseFilesGlob('./lib/**/*.@(ts|js)')
.parseFilesGlob('./lib/**/*.@(ts|js)');

extractor.savePotFile('./l10n/messages.pot')

Expand Down
2 changes: 1 addition & 1 deletion l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"

#: lib/index.ts:22
#: lib/index.ts:20
msgid "seconds"
msgstr ""
18 changes: 8 additions & 10 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import moment from 'moment'
import moment from 'moment/min/moment-with-locales'
import Gettext from 'node-gettext'
import { getLocale } from '@nextcloud/l10n'

const gt = new Gettext()

const locale = getLocale()
LOCALES.forEach((data) => {
gt.addTranslations(data.locale, 'messages', data.json)
})
gt.setLocale(locale)
// eslint-disable-next-line import/no-named-as-default-member
const translations = LOCALES

moment.locale(locale)

// Only update the locale of moment.js if it's available. Moment.js ships more locales than we
// track in transifex, so we prefer the included translation. Always prefer our default english
// translation.
if (locale === 'en' || LOCALES.find(data => data.locale === locale)) {
// eslint-disable-next-line import/no-named-as-default-member
if (locale === 'en' || locale in translations) {
const gt = new Gettext()
gt.addTranslations(locale, 'messages', translations[locale])
gt.setLocale(locale)

moment.updateLocale(moment.locale(), {
relativeTime: {
s: gt.gettext('seconds'),
Expand Down
Loading

0 comments on commit d0a6ca7

Please sign in to comment.