Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/l10n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: L10n
on: pull_request

jobs:
l10n-extract-check:
runs-on: ubuntu-latest
name: Pot check
steps:
- uses: actions/checkout@master
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: npm install
run: npm ci
- name: extract l10n files
run: npm run l10n:extract
- name: Check l10n file changes
run: bash -c "[[ ! \"`git status --porcelain l10n`\" ]] || ( echo 'Uncommited l10n changes. Run `npm l10n:extract`.' && git status && exit 1 )"
11 changes: 2 additions & 9 deletions build/extract-l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ let extractor = new GettextExtractor();

extractor
.createJsParser([
JsExtractors.callExpression('t', {
JsExtractors.callExpression('gt.gettext', {
arguments: {
text: 0,
context: 1
}
}),
JsExtractors.callExpression('n', {
arguments: {
text: 1,
textPlural: 2,
context: 3
}
})
])
.parseFilesGlob('./lib/**/*.@(ts|js)');

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

extractor.printStats();
7 changes: 7 additions & 0 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"

#: lib/index.ts:22
msgid "seconds"
msgstr ""
6 changes: 6 additions & 0 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Translations {
locale: string
json: object
}

declare const LOCALES: Translations[];
16 changes: 10 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import moment from 'moment'
import { getLocale, translate } from '@nextcloud/l10n'
import Gettext from 'node-gettext'
import { getLocale } from '@nextcloud/l10n'

function t(text: string): string {
return translate('nextcloud-moment', text)
}
const gt = new Gettext()

moment.locale(getLocale())
const locale = getLocale()
LOCALES.map(data => {
gt.addTranslations(data.locale, 'messages', data.json)
})
gt.setLocale(locale)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use the language settings for this instead of the locale setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never sure. @nickvergessen knows best

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well see nextcloud/server#14784

So moment JS is actually "fucked up" as it has only one option to set this and is unable to handle a locale being different from the language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then it should be fine for now otherwise it would just be the "seconds" which would be in the proper language, the rest provided by moment would have the language defined by the locale.

moment.locale(locale)

moment.updateLocale(
moment.locale(),
Expand All @@ -15,7 +19,7 @@ moment.updateLocale(
// @ts-ignore
moment.localeData(moment.locale())._relativeTime,
{
s: t('seconds'),
s: gt.gettext('seconds'),
}
)
})
Expand Down
Loading