Skip to content

Commit

Permalink
Merge pull request #572 from nextcloud/fix-registry-warnings
Browse files Browse the repository at this point in the history
Remove warning "No translation for appId "${appId}" have been registered"
  • Loading branch information
ChristophWurst authored Jan 26, 2023
2 parents 1252ea5 + 380bb0a commit 360326b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
6 changes: 0 additions & 6 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ export function unregisterAppTranslations(appId: string) {
* @return {object}
*/
export function getAppTranslations(appId: string): AppTranslations {
if (
typeof window._oc_l10n_registry_translations?.[appId] === 'undefined'
|| typeof window._oc_l10n_registry_plural_functions?.[appId] === 'undefined'
) {
console.warn(`No translation for appId "${appId}" have been registered`)
}
return {
translations: window._oc_l10n_registry_translations?.[appId] ?? {},
pluralFunction: window._oc_l10n_registry_plural_functions?.[appId] ?? ((number: number) => number),
Expand Down
2 changes: 1 addition & 1 deletion tests/gettext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { po } from 'gettext-parser'
import { getGettextBuilder } from '../lib/gettext.ts'

describe('gettext', () => {

beforeEach(() => {
jest.spyOn(console, 'warn')
console.warn.mockImplementation(() => {})
})

afterEach(() => {
Expand Down
14 changes: 0 additions & 14 deletions tests/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ describe('registry', () => {
})

describe('getAppTranslations', () => {
const orginalWarn = console.warn

afterAll(() => {
console.warn = orginalWarn
})
beforeEach(() => {
console.warn = jest.fn()
clearWindow()
})

Expand All @@ -64,7 +58,6 @@ describe('registry', () => {
expect(bundle.translations).toMatchObject({})
expect(typeof bundle.pluralFunction === 'function').toBe(true)
expect(typeof bundle.pluralFunction(0)).toBe('number')
expect(console.warn).toBeCalled()
})

it('with translations', () => {
Expand All @@ -73,17 +66,10 @@ describe('registry', () => {
let bundle = getAppTranslations('core')
expect(Object.keys(bundle.translations).length > 0).toBe(true)
expect(bundle.pluralFunction).toBe(pluralFunction)
expect(console.warn).toBeCalledTimes(0)

bundle = getAppTranslations('doesnotexist')
expect(bundle.translations).toMatchObject({})
expect(typeof bundle.pluralFunction === 'function').toBe(true)
expect(console.warn).toBeCalledTimes(1)

// Expect a warning if some registration is broken
delete window._oc_l10n_registry_plural_functions
bundle = getAppTranslations('core')
expect(console.warn).toBeCalledTimes(2)
})
})

Expand Down

0 comments on commit 360326b

Please sign in to comment.