Skip to content

Commit 943b1bb

Browse files
authored
Merge pull request #974 from teleporthq/feat/ignore-browser-lang
Add flag to next config to enable ignoring browser default language
2 parents 4b724ec + 25dae93 commit 943b1bb

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

packages/teleport-project-generator-next/src/internationalization/project.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,18 @@ export class NextProjectPlugini18nConfig implements ProjectPlugin {
120120
async runAfter(structure: ProjectPluginStructure) {
121121
const { uidl, files, template } = structure
122122

123-
const { languages = { en: 'English' }, main = { locale: 'en', name: 'English' } } =
124-
uidl.internationalization || {}
123+
const {
124+
languages = { en: 'English' },
125+
main = { locale: 'en', name: 'English' },
126+
ignoreBrowserLanguage = false,
127+
} = uidl.internationalization || {}
128+
125129
if (languages !== undefined && Object.keys(languages).length > 0) {
126130
const languageKeys = Object.keys(languages)
127131
const nextConfig = `module.exports = {
128132
i18n: {
129133
locales: [${languageKeys.map((key) => `'${key}'`).join(', ')}],
130-
defaultLocale: "${main.locale}",
134+
defaultLocale: "${main.locale}",${ignoreBrowserLanguage ? '\n localeDetection: false,' : ''}
131135
}
132136
}`
133137
const existingNextConfig =

packages/teleport-types/src/uidl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export interface ProjectUIDL {
9696
}
9797
languages: Record<string, string>
9898
translations: Record<string, Record<string, UIDLElementNode | UIDLStaticValue>>
99+
ignoreBrowserLanguage?: boolean
99100
}
100101
}
101102

packages/teleport-types/src/vuidl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export type VProjectUIDL = Modify<
269269
name: string
270270
locale: string
271271
}
272+
ignoreBrowserLanguage?: boolean
272273
languages: Record<string, string>
273274
translations: Record<string, Record<string, VUIDLElementNode | UIDLStaticValue>>
274275
}

packages/teleport-uidl-validator/src/decoders/project-decoder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
withDefault,
1010
number,
1111
union,
12+
boolean,
1213
} from '@mojotech/json-type-validation'
1314
import {
1415
VUIDLGlobalProjectValues,
@@ -88,6 +89,7 @@ export const projectUIDLDecoder: Decoder<VProjectUIDL> = object({
8889
name: string(),
8990
locale: string(),
9091
}),
92+
ignoreBrowserLanguage: optional(boolean()),
9193
languages: dict(string()),
9294
translations: dict(dict(union(elementNodeDecoder, staticValueDecoder))),
9395
})

0 commit comments

Comments
 (0)