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

Remove warning "No translation for appId "${appId}" have been registered" #572

Merged
merged 2 commits into from Jan 26, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/registry.ts
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
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
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