Skip to content

Commit

Permalink
feat: export aliases t and n for translate and translatePlural
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Feb 10, 2024
1 parent 1388a39 commit 9a355a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ You can use helpers in this package in order generate code that also works when
In order to not break the l10n string extraction scripts, make sure to alias the imported function to match the legacy syntax:

```js
import {translate as t, translatePlural as n} from '@nextcloud/l10n'
import { t, n } from '@nextcloud/l10n'
// Or
import { translate as t, translatePlural as n } from '@nextcloud/l10n'

t('myapp', 'Hello!')
n('myapp', '%n cloud', '%n clouds', 100)
Expand Down
7 changes: 7 additions & 0 deletions lib/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,10 @@ export function getPlural(number: number) {
return 0
}
}

// Export short-hand

export {
translate as t,
translatePlural as n,
}
10 changes: 10 additions & 0 deletions tests/translation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
translate,
translatePlural,
unregister,
t,
n,
} from '../lib/translation'

declare const window: NextcloudWindowWithRegistry
Expand Down Expand Up @@ -139,6 +141,14 @@ describe('translate', () => {
expect(translatePlural('core', ...text, 1)).toBe('Lade 1 Datei von {url} herunter')
expect(translatePlural('core', ...text, 2)).toBe('Lade 2 Dateien von {url} herunter')
})

it('has "t" alias for "translate"', () => {
expect(t).toBe(translate)
})

it('has "n" alias for "translatePlural"', () => {
expect(n).toBe(translatePlural)
})
})

describe('register', () => {
Expand Down

0 comments on commit 9a355a4

Please sign in to comment.