Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: Move package to vite for bundling + compress translations #781

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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