Skip to content

Commit

Permalink
feat(i18n): use last registered locale as default (#5381)
Browse files Browse the repository at this point in the history
Until we land schema localization, choosing a different language has limited value.
For now, select the last registered locale and use that, disabling the choice.
Will fall back to English (US) on missing strings.
  • Loading branch information
rexxars authored Dec 18, 2023
1 parent 2a7aff1 commit 30cbe31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 3 additions & 5 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import {routerDebugTool} from './plugins/router-debug'
import {StegaDebugger} from './schema/debug/components/DebugStega'
import {testStudioLocaleBundles} from './locales'

const localePlugins = [koKRLocale(), nbNOLocale(), nnNOLocale(), ptPTLocale(), svSELocale()]

const sharedSettings = definePlugin({
name: 'sharedSettings',
schema: {
Expand Down Expand Up @@ -93,11 +95,7 @@ const sharedSettings = definePlugin({
},
},
plugins: [
koKRLocale(),
nbNOLocale(),
nnNOLocale(),
ptPTLocale(),
svSELocale(),
// ...localePlugins,
deskTool({
icon: BookIcon,
structure,
Expand Down
3 changes: 2 additions & 1 deletion packages/sanity/src/core/i18n/i18nConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function getI18NextOptions(
): InitOptions & {lng: string} {
const preferredLocaleId = getPreferredLocale(projectId, sourceName)
const preferredLocale = locales.find((l) => l.id === preferredLocaleId)
const locale = preferredLocale?.id ?? locales[0]?.id ?? defaultOptions.lng
const lastLocale = locales[locales.length - 1]
const locale = preferredLocale?.id ?? lastLocale.id ?? defaultOptions.lng
return {
...defaultOptions,
lng: locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import React, {useCallback} from 'react'
import {useTranslation} from '../../../../i18n'
import {useLocale} from '../../../../i18n/hooks/useLocale'

const LOCALE_SELECTION_DISABLED = true

export function LocaleMenu() {
const {changeLocale, currentLocale, locales} = useLocale()
const {t} = useTranslation()

if (LOCALE_SELECTION_DISABLED) {
return null
}

if (!locales || locales.length < 2) {
return null
}
Expand Down

2 comments on commit 30cbe31

@vercel
Copy link

@vercel vercel bot commented on 30cbe31 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 30cbe31 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.