Use defaultVariables to define variables for all translations (#3815)

GitOrigin-RevId: d7b30f523edba7c384d5207a44643acdbbedc74c
This commit is contained in:
Alf Eaton 2021-03-25 10:11:31 +00:00 committed by Copybot
parent 974fe8fd39
commit 79a520dd1c
4 changed files with 17 additions and 16 deletions

View file

@ -25,7 +25,10 @@ i18n.use(initReactI18next).init({
prefix: '__',
suffix: '__',
unescapeSuffix: 'HTML',
skipOnVariables: true
skipOnVariables: true,
defaultVariables: {
appName: 'Overleaf'
}
}
})
@ -84,7 +87,6 @@ const withTheme = (Story, context) => {
export const decorators = [withTheme]
window.ExposedSettings = {
appName: 'Overleaf',
maxEntitiesPerProject: 10,
maxUploadSize: 5 * 1024 * 1024
}

View file

@ -67,12 +67,7 @@ ShareProjectModalContent.propTypes = {
function ErrorMessage({ error }) {
switch (error) {
case 'cannot_invite_non_user':
return (
<Trans
i18nKey="cannot_invite_non_user"
values={{ appName: window.ExposedSettings.appName }}
/>
)
return <Trans i18nKey="cannot_invite_non_user" />
case 'cannot_verify_user_not_robot':
return <Trans i18nKey="cannot_verify_user_not_robot" />

View file

@ -31,7 +31,11 @@ i18n.use(initReactI18next).init({
// Disable nesting in interpolated values, preventing user input
// injection via another nested value
skipOnVariables: true
skipOnVariables: true,
defaultVariables: {
appName: window.ExposedSettings.appName
}
}
})

View file

@ -17,6 +17,13 @@ const chai = require('chai')
chai.use(require('sinon-chai'))
chai.use(require('chai-as-promised'))
// Mock global settings
window.ExposedSettings = {
appName: 'Overleaf',
maxEntitiesPerProject: 10,
maxUploadSize: 5 * 1024 * 1024
}
window.i18n = { currentLangCode: 'en' }
require('../../frontend/js/i18n')
@ -51,13 +58,6 @@ Object.defineProperty(global, 'localStorage', {
const fetch = require('node-fetch')
global.fetch = (url, ...options) => fetch('http://localhost' + url, ...options)
// Mock global settings
window.ExposedSettings = {
appName: 'Overleaf',
maxEntitiesPerProject: 10,
maxUploadSize: 5 * 1024 * 1024
}
// ignore CSS files
const { addHook } = require('pirates')
addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })