-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve default options when adding new translations
Refactored language modules to merge with existing default translations in `videojs.options.language`. This prevents overriding default configurations when calling `videojs.addLanguage`. Changes have been applied across all packages in the monorepo and the templates for the generation of new packages. Other changes: - Removed spaces from the skip button translation keys. - Expose language files as assets into the final build.
- Loading branch information
Showing
12 changed files
with
284 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import * as de from './de.json'; | ||
import * as en from './en.json'; | ||
import * as fr from './fr.json'; | ||
import * as it from './it.json'; | ||
import * as rm from './rm.json'; | ||
import de from './de.json'; | ||
import en from './en.json'; | ||
import fr from './fr.json'; | ||
import it from './it.json'; | ||
import rm from './rm.json'; | ||
import videojs from 'video.js'; | ||
|
||
videojs.addLanguage('de', de); | ||
videojs.addLanguage('en', en); | ||
videojs.addLanguage('fr', fr); | ||
videojs.addLanguage('it', it); | ||
videojs.addLanguage('rm', rm); | ||
function extendLanguage(code, data) { | ||
videojs.addLanguage(code, { | ||
...videojs.options.language[code] ?? {}, | ||
...data | ||
}); | ||
} | ||
|
||
extendLanguage('de', de); | ||
extendLanguage('en', en); | ||
extendLanguage('fr', fr); | ||
extendLanguage('it', it); | ||
extendLanguage('rm', rm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import '../src/lang'; | ||
import pillarbox from '@srgssr/pillarbox-web'; | ||
|
||
window.HTMLMediaElement.prototype.load = () => {}; | ||
|
||
describe('Language', () => { | ||
let player; | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = '<video id="test-video" class="video-js"></video>'; | ||
|
||
const videoElement = document.querySelector('#test-video'); | ||
|
||
player = pillarbox(videoElement); | ||
}); | ||
|
||
afterEach(() => { | ||
player.dispose(); | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('should use the correct French translations', () => { | ||
// When | ||
player.language('fr'); | ||
|
||
// Then | ||
expect(player.localize('Play')).toBe('Lecture'); | ||
expect(player.localize('Shuffle')).toBe('Mélanger'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import * as de from './de.json'; | ||
import * as en from './en.json'; | ||
import * as fr from './fr.json'; | ||
import * as it from './it.json'; | ||
import * as rm from './rm.json'; | ||
import de from './de.json'; | ||
import en from './en.json'; | ||
import fr from './fr.json'; | ||
import it from './it.json'; | ||
import rm from './rm.json'; | ||
import pillarbox from '@srgssr/pillarbox-web'; | ||
|
||
pillarbox.addLanguage('de', de); | ||
pillarbox.addLanguage('en', en); | ||
pillarbox.addLanguage('fr', fr); | ||
pillarbox.addLanguage('it', it); | ||
pillarbox.addLanguage('rm', rm); | ||
function extendLanguage(code, data) { | ||
pillarbox.addLanguage(code, { | ||
...pillarbox.options.language[code] ?? {}, | ||
...data | ||
}); | ||
} | ||
|
||
extendLanguage('de', de); | ||
extendLanguage('en', en); | ||
extendLanguage('fr', fr); | ||
extendLanguage('it', it); | ||
extendLanguage('rm', rm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import '../src/lang'; | ||
import pillarbox from '@srgssr/pillarbox-web'; | ||
|
||
window.HTMLMediaElement.prototype.load = () => {}; | ||
|
||
describe('Language', () => { | ||
let player; | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = '<video id="test-video" class="video-js"></video>'; | ||
|
||
const videoElement = document.querySelector('#test-video'); | ||
|
||
player = pillarbox(videoElement); | ||
}); | ||
|
||
afterEach(() => { | ||
player.dispose(); | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('should use the correct French translations', () => { | ||
// When | ||
player.language('fr'); | ||
|
||
// Then | ||
expect(player.localize('Play')).toBe('Lecture'); | ||
expect(player.localize('Skip credits')).toBe('Passer'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import * as de from './de.json'; | ||
import * as en from './en.json'; | ||
import * as fr from './fr.json'; | ||
import * as it from './it.json'; | ||
import * as rm from './rm.json'; | ||
import de from './de.json'; | ||
import en from './en.json'; | ||
import fr from './fr.json'; | ||
import it from './it.json'; | ||
import rm from './rm.json'; | ||
import {{platform}} from '{{importAlias}}'; | ||
|
||
{{platform}}.addLanguage('de', de); | ||
{{platform}}.addLanguage('en', en); | ||
{{platform}}.addLanguage('fr', fr); | ||
{{platform}}.addLanguage('it', it); | ||
{{platform}}.addLanguage('rm', rm); | ||
function extendLanguage(code, data) { | ||
{{platform}}.addLanguage(code, { | ||
...{{platform}}.options.language[code] ?? {}, | ||
...data | ||
}); | ||
} | ||
|
||
extendLanguage('de', de); | ||
extendLanguage('en', en); | ||
extendLanguage('fr', fr); | ||
extendLanguage('it', it); | ||
extendLanguage('rm', rm); |
Oops, something went wrong.