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 a967ad2
Show file tree
Hide file tree
Showing 14 changed files with 3,826 additions and 21,790 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
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 a967ad2

Please sign in to comment.