Skip to content

Commit d64ffe0

Browse files
Merge pull request #10 from pexip/6-add-support-for-i18n
feat: add support for i18n
2 parents 97723af + 0103322 commit d64ffe0

9 files changed

Lines changed: 491 additions & 475 deletions

File tree

package-lock.json

Lines changed: 404 additions & 450 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
"license": "ISC",
1414
"type": "module",
1515
"dependencies": {
16-
"@pexip/plugin-api": "21.1.1",
16+
"@pexip/plugin-api": "21.1.2",
17+
"i18next": "^25.3.2",
18+
"i18next-http-backend": "^3.0.2",
1719
"pino": "^9.7.0"
1820
},
1921
"devDependencies": {
20-
"eslint": "^9.31.0",
22+
"eslint": "^9.32.0",
2123
"eslint-config-love": "^121.0.0",
22-
"eslint-config-prettier": "^10.1.5",
24+
"eslint-config-prettier": "^10.1.8",
2325
"prettier": "^3.6.2",
2426
"typescript": "^5.8.3",
25-
"vite": "^7.0.4",
26-
"vite-plugin-mkcert": "^1.17.8"
27+
"vite": "^7.0.6"
2728
}
2829
}

public/locales/en/translation.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"setMessageOverlay": "Set message overlay",
3+
"roomMessage": "Room message",
4+
"message": "message",
5+
"enterYourMessage": "Enter your message",
6+
"selectRoom": "Select room",
7+
"allRooms": "All rooms",
8+
"mainRoom": "Main room",
9+
"submit": "Submit",
10+
"choose": "Choose",
11+
"inputMessageForm": {
12+
"description": "Write your message overlay text below. If you would like to get a new line press enter or make a new line in the textarea."
13+
},
14+
"selectRoomForm": {
15+
"description": "Choose the room you want to set the message overlay for."
16+
}
17+
}

public/locales/nl/translation.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"setMessageOverlay": "Stel berichtoverlay in",
3+
"roomMessage": "Kamerbericht",
4+
"message": "bericht",
5+
"enterYourMessage": "Voer uw bericht in",
6+
"selectRoom": "Selecteer kamer",
7+
"allRooms": "Alle kamers",
8+
"mainRoom": "Hoofdkamer",
9+
"submit": "Verzenden",
10+
"choose": "Kiezen",
11+
"inputMessageForm": {
12+
"description": "Schrijf hieronder uw berichtoverlaytekst. Als u een nieuwe regel wilt, druk op enter of maak een nieuwe regel in het tekstvak."
13+
},
14+
"selectRoomForm": {
15+
"description": "Kies de kamer waarvoor u de berichtoverlay wilt instellen."
16+
}
17+
}

src/forms/createInputMessageForm.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { logger } from '../logger'
22
import { setMessageOverlay } from '../messageOverlay'
33
import { plugin } from '../plugin'
4+
import { i18next } from '../i18n'
45

56
export const createInputMessageForm = async (
67
roomId: string,
@@ -9,27 +10,28 @@ export const createInputMessageForm = async (
910
breakoutRooms?: Map<string, string>
1011
): Promise<void> => {
1112
const messageName =
12-
roomName != null ? `"${roomName}" message` : 'Room message'
13+
roomName != null
14+
? `"${roomName}" ${i18next.t('message')}`
15+
: i18next.t('roomMessage')
1316

1417
if (plugin == null) {
1518
throw new Error('Plugin is not initialized.')
1619
}
1720

1821
const form = await plugin.ui.addForm({
19-
title: 'Set message overlay',
20-
description:
21-
'Write your message overlay text below. If you would like to get a new line press enter or make a new line in the textarea',
22+
title: i18next.t('setMessageOverlay'),
23+
description: i18next.t('inputMessageForm.description'),
2224
form: {
2325
elements: {
2426
message: {
2527
name: messageName,
2628
type: 'textarea',
2729
isOptional: true,
28-
placeholder: 'Enter your message',
30+
placeholder: i18next.t('enterYourMessage'),
2931
value: currentMessage
3032
}
3133
},
32-
submitBtnTitle: 'Submit'
34+
submitBtnTitle: i18next.t('submit')
3335
}
3436
})
3537

src/forms/createSelectRoomForm.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createInputMessageForm } from './createInputMessageForm'
22
import { getMessageOverlay } from '../messageOverlay'
33
import { plugin } from '../plugin'
44
import { logger } from '../logger'
5+
import { i18next } from '../i18n'
56

67
export const createSelectRoomForm = async (
78
breakoutRooms: Map<string, string>
@@ -11,22 +12,22 @@ export const createSelectRoomForm = async (
1112
}
1213

1314
const form = await plugin.ui.addForm({
14-
title: 'Set message overlay',
15-
description: 'Choose the room you want to set the message overlay for.',
15+
title: i18next.t('setMessageOverlay'),
16+
description: i18next.t('selectRoomForm.description'),
1617
form: {
1718
elements: {
1819
room: {
19-
name: 'Select room',
20+
name: i18next.t('selectRoom'),
2021
type: 'select',
2122
isOptional: true,
2223
options: [
2324
{
2425
id: '',
25-
label: 'All rooms'
26+
label: i18next.t('allRooms')
2627
},
2728
{
2829
id: 'main',
29-
label: 'Main room'
30+
label: i18next.t('mainRoom')
3031
},
3132
...Array.from(breakoutRooms).map(([roomId, roomName]) => ({
3233
id: roomId,
@@ -35,7 +36,7 @@ export const createSelectRoomForm = async (
3536
]
3637
}
3738
},
38-
submitBtnTitle: 'Choose'
39+
submitBtnTitle: i18next.t('choose')
3940
}
4041
})
4142

@@ -55,9 +56,9 @@ export const createSelectRoomForm = async (
5556

5657
const roomName =
5758
roomId === ''
58-
? 'All rooms'
59+
? i18next.t('allRooms')
5960
: roomId === 'main'
60-
? 'Main room'
61+
? i18next.t('mainRoom')
6162
: breakoutRooms.get(roomId)
6263

6364
await createInputMessageForm(roomId, currentMessage, roomName)

src/i18n.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import i18next from 'i18next'
2+
import Backend from 'i18next-http-backend'
3+
import { logger } from './logger'
4+
5+
export const initI18n = async (): Promise<void> => {
6+
logger.info('Initializing i18n...')
7+
await i18next.use(Backend).init({
8+
fallbackLng: 'en',
9+
backend: {
10+
loadPath: 'locales/{{lng}}/{{ns}}.json'
11+
}
12+
})
13+
}
14+
15+
initI18n().catch((error: unknown) => {
16+
logger.error('Failed to initialize i18n:', error)
17+
})
18+
19+
export { i18next }

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getMessageOverlay } from './messageOverlay'
44
import { createInputMessageForm } from './forms/createInputMessageForm'
55
import { setPlugin } from './plugin'
66
import { logger } from './logger'
7+
import { i18next } from './i18n'
78

89
const version = 1
910

@@ -43,6 +44,14 @@ plugin.events.conferenceStatus.add(async ({ id, status }) => {
4344
}
4445
})
4546

47+
plugin.events.languageSelect.add(async (language) => {
48+
await i18next.changeLanguage(language).catch(logger.error)
49+
if (button != null) {
50+
await removeButton()
51+
await addButton()
52+
}
53+
})
54+
4655
const addButton = async (): Promise<void> => {
4756
if (button != null || creatingButton) {
4857
return
@@ -51,7 +60,7 @@ const addButton = async (): Promise<void> => {
5160
creatingButton = true
5261
button = await plugin.ui.addButton({
5362
position: 'settingsMenu',
54-
label: 'Set message overlay',
63+
label: i18next.t('setMessageOverlay'),
5564
inMeetingOnly: true,
5665
roles: ['chair']
5766
})

vite.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/* eslint-disable @typescript-eslint/restrict-plus-operands */
22
import { defineConfig } from 'vite'
3-
import mkcert from 'vite-plugin-mkcert'
43

54
export default defineConfig({
65
base: './',
76
build: {
87
target: 'esnext'
9-
},
10-
plugins: [
11-
mkcert()
12-
]
8+
}
139
})

0 commit comments

Comments
 (0)