@antelopejs/dms-lang 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/pages/actions.d.ts +7 -0
- package/dist/pages/actions.js +15 -0
- package/dist/pages/actions.js.map +1 -0
- package/dist/pages/component-action.d.ts +2 -0
- package/dist/pages/component-action.js +10 -0
- package/dist/pages/component-action.js.map +1 -0
- package/dist/pages/header-actions.d.ts +9 -0
- package/dist/pages/header-actions.js +146 -0
- package/dist/pages/header-actions.js.map +1 -0
- package/dist/pages/index.d.ts +6 -0
- package/dist/pages/index.js +6 -0
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/language.d.ts +10 -0
- package/dist/pages/language.js +89 -0
- package/dist/pages/language.js.map +1 -0
- package/dist/pages/languages-table.d.ts +2 -0
- package/dist/pages/languages-table.js +120 -0
- package/dist/pages/languages-table.js.map +1 -0
- package/dist/pages/module.d.ts +7 -1
- package/dist/pages/module.js +28 -2
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.d.ts +2 -1
- package/dist/pages/overview.js +83 -8
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/page-actions.d.ts +6 -0
- package/dist/pages/page-actions.js +10 -0
- package/dist/pages/page-actions.js.map +1 -0
- package/dist/pages/quick-actions.d.ts +1 -0
- package/dist/pages/quick-actions.js +56 -0
- package/dist/pages/quick-actions.js.map +1 -0
- package/dist/pages/translations.d.ts +7 -1
- package/dist/pages/translations.js +47 -10
- package/dist/pages/translations.js.map +1 -1
- package/dist/pages/workspace-guard.d.ts +1 -0
- package/dist/pages/workspace-guard.js +35 -0
- package/dist/pages/workspace-guard.js.map +1 -0
- package/dist/pages/workspace.d.ts +18 -0
- package/dist/pages/workspace.js +162 -0
- package/dist/pages/workspace.js.map +1 -0
- package/dist/pages/workspaces.d.ts +14 -0
- package/dist/pages/workspaces.js +88 -0
- package/dist/pages/workspaces.js.map +1 -0
- package/dist/routes/publicLocales.d.ts +3 -2
- package/dist/routes/publicLocales.js +39 -18
- package/dist/routes/publicLocales.js.map +1 -1
- package/dist/routes/translations.d.ts +59 -63
- package/dist/routes/translations.js +400 -119
- package/dist/routes/translations.js.map +1 -1
- package/dist/utils/announce.d.ts +9 -0
- package/dist/utils/announce.js +29 -0
- package/dist/utils/announce.js.map +1 -0
- package/dist/utils/blocks.d.ts +8 -0
- package/dist/utils/blocks.js +213 -0
- package/dist/utils/blocks.js.map +1 -0
- package/dist/utils/body.d.ts +1 -0
- package/dist/utils/body.js +21 -0
- package/dist/utils/body.js.map +1 -0
- package/dist/utils/cache.d.ts +3 -0
- package/dist/utils/cache.js +32 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/catalog.d.ts +7 -0
- package/dist/utils/catalog.js +62 -0
- package/dist/utils/catalog.js.map +1 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +10 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coverage.d.ts +2 -0
- package/dist/utils/coverage.js +11 -0
- package/dist/utils/coverage.js.map +1 -0
- package/dist/utils/dialogs.d.ts +7 -0
- package/dist/utils/dialogs.js +103 -0
- package/dist/utils/dialogs.js.map +1 -0
- package/dist/utils/errors.d.ts +40 -0
- package/dist/utils/errors.js +60 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/export.d.ts +17 -0
- package/dist/utils/export.js +129 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/json.d.ts +10 -1
- package/dist/utils/json.js +127 -19
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/key-stores.d.ts +3 -0
- package/dist/utils/key-stores.js +24 -0
- package/dist/utils/key-stores.js.map +1 -0
- package/dist/utils/keys.d.ts +23 -0
- package/dist/utils/keys.js +252 -0
- package/dist/utils/keys.js.map +1 -0
- package/dist/utils/languages.d.ts +27 -0
- package/dist/utils/languages.js +121 -0
- package/dist/utils/languages.js.map +1 -0
- package/dist/utils/locale-codes.d.ts +5 -0
- package/dist/utils/locale-codes.js +56 -0
- package/dist/utils/locale-codes.js.map +1 -0
- package/dist/utils/locale-discovery.d.ts +1 -0
- package/dist/utils/locale-discovery.js +19 -1
- package/dist/utils/locale-discovery.js.map +1 -1
- package/dist/utils/message-check.d.ts +1 -0
- package/dist/utils/message-check.js +93 -0
- package/dist/utils/message-check.js.map +1 -0
- package/dist/utils/message-syntax.d.ts +6 -0
- package/dist/utils/message-syntax.js +38 -0
- package/dist/utils/message-syntax.js.map +1 -0
- package/dist/utils/namespaces.d.ts +12 -0
- package/dist/utils/namespaces.js +52 -0
- package/dist/utils/namespaces.js.map +1 -0
- package/dist/utils/notices.d.ts +4 -0
- package/dist/utils/notices.js +60 -0
- package/dist/utils/notices.js.map +1 -0
- package/dist/utils/own.d.ts +2 -3
- package/dist/utils/own.js +17 -57
- package/dist/utils/own.js.map +1 -1
- package/dist/utils/public-url.d.ts +8 -0
- package/dist/utils/public-url.js +87 -0
- package/dist/utils/public-url.js.map +1 -0
- package/dist/utils/registry.d.ts +3 -1
- package/dist/utils/registry.js +26 -10
- package/dist/utils/registry.js.map +1 -1
- package/dist/utils/resolve.d.ts +18 -15
- package/dist/utils/resolve.js +98 -151
- package/dist/utils/resolve.js.map +1 -1
- package/dist/utils/review.d.ts +5 -0
- package/dist/utils/review.js +64 -0
- package/dist/utils/review.js.map +1 -0
- package/dist/utils/snippets.d.ts +7 -0
- package/dist/utils/snippets.js +129 -0
- package/dist/utils/snippets.js.map +1 -0
- package/dist/utils/summary.d.ts +23 -0
- package/dist/utils/summary.js +65 -0
- package/dist/utils/summary.js.map +1 -0
- package/dist/utils/tree.d.ts +2 -17
- package/dist/utils/tree.js +21 -126
- package/dist/utils/tree.js.map +1 -1
- package/dist/utils/workspaces.d.ts +45 -15
- package/dist/utils/workspaces.js +256 -164
- package/dist/utils/workspaces.js.map +1 -1
- package/dist/validation/key.schema.d.ts +71 -0
- package/dist/validation/key.schema.js +67 -0
- package/dist/validation/key.schema.js.map +1 -0
- package/dist/validation/query.schema.d.ts +17 -0
- package/dist/validation/query.schema.js +44 -0
- package/dist/validation/query.schema.js.map +1 -0
- package/dist/validation/validate.d.ts +2 -0
- package/dist/validation/validate.js +24 -0
- package/dist/validation/validate.js.map +1 -0
- package/dist/validation/workspace.schema.d.ts +145 -0
- package/dist/validation/workspace.schema.js +83 -0
- package/dist/validation/workspace.schema.js.map +1 -0
- package/frontend-vue/app/build/components/KeyAddModal.vue +340 -0
- package/frontend-vue/app/build/components/KeyEditorDrawer.vue +951 -0
- package/frontend-vue/app/build/components/KeyRenameModal.vue +172 -0
- package/frontend-vue/app/build/components/LanguageAddModal.vue +199 -0
- package/frontend-vue/app/build/components/LanguagePicker.vue +233 -0
- package/frontend-vue/app/build/components/LocaleTile.vue +52 -0
- package/frontend-vue/app/build/components/PlaceholderText.vue +42 -0
- package/frontend-vue/app/build/components/ShortcutKbds.vue +22 -0
- package/frontend-vue/app/build/components/WorkspaceCreateModal.vue +193 -0
- package/frontend-vue/app/build/components/WorkspaceRenameModal.vue +107 -0
- package/frontend-vue/app/build/components/form/FormFieldRow.vue +70 -0
- package/frontend-vue/app/build/components/form/FormRows.vue +25 -0
- package/frontend-vue/app/build/components/form/WorkspaceDetailsFields.vue +44 -0
- package/frontend-vue/app/build/components/matrix/MatrixCell.vue +488 -0
- package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +177 -0
- package/frontend-vue/app/build/components/matrix/MatrixGroupHeader.vue +57 -0
- package/frontend-vue/app/build/components/matrix/MatrixKeyCell.vue +83 -0
- package/frontend-vue/app/build/components/matrix/MatrixToolbar.vue +167 -0
- package/frontend-vue/app/build/components/queue/QueueActions.vue +60 -0
- package/frontend-vue/app/build/components/queue/QueueDone.vue +185 -0
- package/frontend-vue/app/build/components/queue/QueueEditor.vue +374 -0
- package/frontend-vue/app/build/components/queue/QueueHeader.vue +162 -0
- package/frontend-vue/app/build/components/queue/QueueUpNext.vue +61 -0
- package/frontend-vue/app/build/composables/useCellEditor.ts +324 -0
- package/frontend-vue/app/build/composables/useCellMoves.ts +155 -0
- package/frontend-vue/app/build/composables/useCellSaves.ts +339 -0
- package/frontend-vue/app/build/composables/useKeyPanel.ts +284 -0
- package/frontend-vue/app/build/composables/useKeySaves.ts +280 -0
- package/frontend-vue/app/build/composables/useMatrixFilters.ts +213 -0
- package/frontend-vue/app/build/composables/useMatrixRows.ts +104 -0
- package/frontend-vue/app/build/composables/useMatrixView.ts +181 -0
- package/frontend-vue/app/build/composables/useQueueContext.ts +31 -0
- package/frontend-vue/app/build/composables/useQueueEditing.ts +53 -0
- package/frontend-vue/app/build/composables/useQueueOrphans.ts +54 -0
- package/frontend-vue/app/build/composables/useQueueSave.ts +290 -0
- package/frontend-vue/app/build/composables/useQueueShortcuts.ts +106 -0
- package/frontend-vue/app/build/composables/useQueueToasts.ts +99 -0
- package/frontend-vue/app/components/LanguageNamespaces.vue +77 -0
- package/frontend-vue/app/components/NamespaceCoverage.vue +222 -0
- package/frontend-vue/app/components/TranslationMatrix.vue +809 -0
- package/frontend-vue/app/components/TranslationQueue.vue +212 -0
- package/frontend-vue/app/components/WorkspaceDangerZone.vue +81 -0
- package/frontend-vue/app/components/WorkspaceGeneral.vue +232 -0
- package/frontend-vue/app/components/WorkspaceList.vue +454 -0
- package/frontend-vue/app/components/WorkspaceScope.vue +384 -0
- package/frontend-vue/app/composables/translation/useFirstRun.ts +8 -0
- package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +221 -133
- package/frontend-vue/app/composables/translation/useKeyActions.ts +224 -0
- package/frontend-vue/app/composables/translation/useLangFormat.ts +10 -0
- package/frontend-vue/app/composables/translation/useLangLinks.ts +80 -0
- package/frontend-vue/app/composables/translation/useLanguageActions.ts +159 -0
- package/frontend-vue/app/composables/translation/useLanguageQueue.ts +232 -0
- package/frontend-vue/app/composables/translation/useLocaleNames.ts +166 -0
- package/frontend-vue/app/composables/translation/useMutationToast.ts +51 -17
- package/frontend-vue/app/composables/translation/useQueueDrafts.ts +115 -0
- package/frontend-vue/app/composables/translation/useQueueSession.ts +182 -0
- package/frontend-vue/app/composables/translation/useServedConfirm.ts +152 -0
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +259 -0
- package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +46 -15
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +322 -70
- package/frontend-vue/app/composables/translation/useWorkspaceNameCheck.ts +55 -0
- package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +129 -0
- package/frontend-vue/app/config/shortcuts-registry.ts +72 -0
- package/frontend-vue/app/types/lang.ts +130 -0
- package/frontend-vue/app/utils/boundedCache.ts +22 -0
- package/frontend-vue/app/utils/download.ts +16 -0
- package/frontend-vue/app/utils/keySaveErrors.ts +61 -0
- package/frontend-vue/app/utils/keySaves.ts +108 -0
- package/frontend-vue/app/utils/languages.ts +272 -0
- package/frontend-vue/app/utils/matrixExport.ts +47 -0
- package/frontend-vue/app/utils/queueDrafts.ts +115 -0
- package/frontend-vue/app/utils/queuePass.ts +145 -0
- package/frontend-vue/app/utils/queueView.ts +22 -0
- package/frontend-vue/app/utils/shortcuts.ts +75 -0
- package/frontend-vue/app/utils/translations.ts +756 -0
- package/frontend-vue/app/utils/workspaceBackup.ts +119 -0
- package/frontend-vue/app/utils/workspaces.ts +45 -0
- package/frontend-vue/dms.frontend.build.ts +5 -0
- package/frontend-vue/dms.frontend.ts +9 -20
- package/frontend-vue/i18n/locales/lang-en-GB.json +792 -69
- package/frontend-vue/i18n/locales/lang-fr-FR.json +792 -69
- package/frontend-vue/package.json +8 -6
- package/package.json +8 -6
- package/dist/utils/mutations.d.ts +0 -3
- package/dist/utils/mutations.js +0 -35
- package/dist/utils/mutations.js.map +0 -1
- package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
- package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
- package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
- package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
- package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
- package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
- package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
- package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
- package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
- package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
- package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +0 -12
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const MODULE_BASE = '/modules/lang'
|
|
2
|
+
|
|
3
|
+
export const LANG_PAGES = {
|
|
4
|
+
overview: `${MODULE_BASE}/overview`,
|
|
5
|
+
translations: `${MODULE_BASE}/translations`,
|
|
6
|
+
language: `${MODULE_BASE}/language`,
|
|
7
|
+
workspaces: `${MODULE_BASE}/workspaces`,
|
|
8
|
+
workspace: `${MODULE_BASE}/workspace`,
|
|
9
|
+
} as const
|
|
10
|
+
|
|
11
|
+
export type LangPage = keyof typeof LANG_PAGES
|
|
12
|
+
|
|
13
|
+
export type PageQuery = Record<string, string | undefined>
|
|
14
|
+
|
|
15
|
+
/** The query a page reads to open one of its dialogs on arrival. */
|
|
16
|
+
export const PAGE_ACTION_QUERY = 'action'
|
|
17
|
+
|
|
18
|
+
export const PAGE_ACTIONS = {
|
|
19
|
+
addLanguage: 'add-language',
|
|
20
|
+
addKey: 'add-key',
|
|
21
|
+
newWorkspace: 'new-workspace',
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
export const LOCALE_PLACEHOLDER = '{locale}'
|
|
25
|
+
|
|
26
|
+
export function linkWithQuery(path: string, query: PageQuery): string {
|
|
27
|
+
const params = new URLSearchParams()
|
|
28
|
+
for (const [name, value] of Object.entries(query)) {
|
|
29
|
+
if (value) params.set(name, value)
|
|
30
|
+
}
|
|
31
|
+
const search = params.toString()
|
|
32
|
+
return search ? `${path}?${search}` : path
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The module page a path shows, if it is one. */
|
|
36
|
+
export function langPageOf(path: string): LangPage | undefined {
|
|
37
|
+
const entries = Object.entries(LANG_PAGES) as [LangPage, string][]
|
|
38
|
+
return entries.find(([, pagePath]) => pagePath === path)?.[0]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Links to the pages of the module, each carrying the selected workspace, and
|
|
43
|
+
* the public URL the server gives a workspace's language files.
|
|
44
|
+
*/
|
|
45
|
+
export const useLangLinks = () => {
|
|
46
|
+
const { selectedWorkspace, workspaces, publicBaseUrl } = useI18nWorkspaces()
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The URL another app loads a language from: the one the server computed
|
|
50
|
+
* for an existing workspace, built on the server's base for a name being
|
|
51
|
+
* chosen. Empty for the workspaces `/i18n` does not serve.
|
|
52
|
+
*/
|
|
53
|
+
function publicLocaleUrl(workspace: string, locale = LOCALE_PLACEHOLDER) {
|
|
54
|
+
const known = workspaces.value.find((entry) => entry.id === workspace)
|
|
55
|
+
if (known && known.kind !== 'added') return ''
|
|
56
|
+
const template =
|
|
57
|
+
known?.publicUrl ??
|
|
58
|
+
`${publicBaseUrl.value}/${workspace}/${LOCALE_PLACEHOLDER}.json`
|
|
59
|
+
return template.replace(LOCALE_PLACEHOLDER, locale)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function pageLink(page: LangPage, query: PageQuery = {}): string {
|
|
63
|
+
return linkWithQuery(LANG_PAGES[page], {
|
|
64
|
+
workspace: selectedWorkspace.value,
|
|
65
|
+
...query,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
pageLink,
|
|
71
|
+
publicLocaleUrl,
|
|
72
|
+
overview: (query: PageQuery = {}) => pageLink('overview', query),
|
|
73
|
+
translations: (query: PageQuery = {}) => pageLink('translations', query),
|
|
74
|
+
language: (locale: string, query: PageQuery = {}) =>
|
|
75
|
+
pageLink('language', { locale, ...query }),
|
|
76
|
+
workspaces: (query: PageQuery = {}) => pageLink('workspaces', query),
|
|
77
|
+
workspaceSettings: (workspace?: string) =>
|
|
78
|
+
pageLink('workspace', workspace ? { workspace } : {}),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { until } from '@vueuse/core'
|
|
3
|
+
import { useDmsState } from '#dms/frontend-module'
|
|
4
|
+
import LanguageAddModal from '../../build/components/LanguageAddModal.vue'
|
|
5
|
+
|
|
6
|
+
/** What the language actions share: the selected workspace and the DMS helpers. */
|
|
7
|
+
interface LanguageActionsContext {
|
|
8
|
+
t: ReturnType<typeof useI18n>['t']
|
|
9
|
+
toast: ReturnType<typeof useToast>
|
|
10
|
+
overlay: ReturnType<typeof useOverlay>
|
|
11
|
+
confirmServed: ReturnType<typeof useServedConfirm>
|
|
12
|
+
formatCount: ReturnType<typeof useLangFormat>['formatCount']
|
|
13
|
+
workspaces: ReturnType<typeof useI18nWorkspaces>
|
|
14
|
+
translations: ReturnType<typeof useWorkspaceFlat>
|
|
15
|
+
current: ReturnType<typeof useWorkspaceContext>['current']
|
|
16
|
+
canManage: Ref<boolean>
|
|
17
|
+
nativeName: (code: string) => string
|
|
18
|
+
isAddOpen: Ref<boolean>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const REMOVAL_CONFIRM = 'removal-confirm'
|
|
22
|
+
const BASE_CONFIRM = 'base-confirm'
|
|
23
|
+
|
|
24
|
+
function notify(context: LanguageActionsContext, title: string) {
|
|
25
|
+
context.toast.add({ title, color: 'success', icon: 'i-ph-check-circle' })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function codesOf(context: LanguageActionsContext): string[] {
|
|
29
|
+
return context.current.value?.locales.map((locale) => locale.code) ?? []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Settles once every closed dialog has finished leaving the screen. */
|
|
33
|
+
function dialogsLeft(context: LanguageActionsContext): Promise<boolean> {
|
|
34
|
+
const { overlays } = context.overlay
|
|
35
|
+
return until(() =>
|
|
36
|
+
overlays.some((entry) => entry.isMounted && !entry.isOpen),
|
|
37
|
+
).toBe(false)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function explainLocked({ t, toast }: LanguageActionsContext): void {
|
|
41
|
+
toast.add({
|
|
42
|
+
title: t('dms_lang.language_add.locked_title'),
|
|
43
|
+
description: t('dms_lang.language_add.locked'),
|
|
44
|
+
color: 'warning',
|
|
45
|
+
icon: 'i-ph-lock-simple',
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function openAddModal(context: LanguageActionsContext): Promise<boolean> {
|
|
50
|
+
context.isAddOpen.value = true
|
|
51
|
+
try {
|
|
52
|
+
const modal = context.overlay.create(LanguageAddModal, {
|
|
53
|
+
props: {
|
|
54
|
+
workspace: context.workspaces.selectedWorkspace.value,
|
|
55
|
+
existing: codesOf(context),
|
|
56
|
+
baseName: context.nativeName(context.current.value?.defaultLocale ?? ''),
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
return (await modal.open()) === true
|
|
60
|
+
} finally {
|
|
61
|
+
context.isAddOpen.value = false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function addLanguage(context: LanguageActionsContext): Promise<boolean> {
|
|
66
|
+
if (!context.canManage.value) {
|
|
67
|
+
explainLocked(context)
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
if (context.isAddOpen.value) return false
|
|
71
|
+
const before = new Set(codesOf(context))
|
|
72
|
+
if (!(await openAddModal(context))) return false
|
|
73
|
+
await context.translations.refresh()
|
|
74
|
+
const code = codesOf(context).find((locale) => !before.has(locale))
|
|
75
|
+
if (!code) return true
|
|
76
|
+
const total = context.current.value?.totalKeys ?? 0
|
|
77
|
+
const params = {
|
|
78
|
+
name: context.nativeName(code),
|
|
79
|
+
code,
|
|
80
|
+
count: context.formatCount(total),
|
|
81
|
+
}
|
|
82
|
+
notify(context, context.t('dms_lang.language_add.done', params, total))
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function languageRoute(context: LanguageActionsContext, code: string): string {
|
|
87
|
+
return languageUrl(context.workspaces.selectedWorkspace.value, code)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Asks with the server's dialog, then removes a language. `afterRemove`
|
|
92
|
+
* runs once the dialog has left the screen (the Language page leaves for
|
|
93
|
+
* the overview there), before the data of the page is read again.
|
|
94
|
+
*/
|
|
95
|
+
async function removeLanguage(
|
|
96
|
+
context: LanguageActionsContext,
|
|
97
|
+
code: string,
|
|
98
|
+
afterRemove?: () => Promise<unknown>,
|
|
99
|
+
): Promise<boolean> {
|
|
100
|
+
const workspace = context.workspaces.selectedWorkspace.value
|
|
101
|
+
const route = languageRoute(context, code)
|
|
102
|
+
const removed = await context.confirmServed(
|
|
103
|
+
`${route}/${REMOVAL_CONFIRM}`,
|
|
104
|
+
() => context.workspaces.removeLocale(workspace, code),
|
|
105
|
+
)
|
|
106
|
+
if (!removed) return false
|
|
107
|
+
notify(context, context.t('dms_lang.language_remove.done'))
|
|
108
|
+
await dialogsLeft(context)
|
|
109
|
+
await afterRemove?.()
|
|
110
|
+
await context.translations.refresh()
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Makes a language the base of the workspace, once the user saw in the
|
|
116
|
+
* server's dialog which keys have no text in it: they show as missing in
|
|
117
|
+
* the base afterwards.
|
|
118
|
+
*/
|
|
119
|
+
async function makeBase(
|
|
120
|
+
context: LanguageActionsContext,
|
|
121
|
+
code: string,
|
|
122
|
+
): Promise<boolean> {
|
|
123
|
+
const workspace = context.workspaces.selectedWorkspace.value
|
|
124
|
+
const route = languageRoute(context, code)
|
|
125
|
+
const confirmed = await context.confirmServed(`${route}/${BASE_CONFIRM}`, () =>
|
|
126
|
+
context.workspaces.setDefaultLocale(workspace, code),
|
|
127
|
+
)
|
|
128
|
+
if (!confirmed) return false
|
|
129
|
+
await context.translations.refresh()
|
|
130
|
+
notify(
|
|
131
|
+
context,
|
|
132
|
+
context.t('dms_lang.language_base.done', { name: context.nativeName(code) }),
|
|
133
|
+
)
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Add, remove and make base a language of the selected workspace. */
|
|
138
|
+
export const useLanguageActions = () => {
|
|
139
|
+
const { current, canManage } = useWorkspaceContext()
|
|
140
|
+
const context: LanguageActionsContext = {
|
|
141
|
+
t: useI18n().t,
|
|
142
|
+
toast: useToast(),
|
|
143
|
+
overlay: useOverlay(),
|
|
144
|
+
confirmServed: useServedConfirm(),
|
|
145
|
+
formatCount: useLangFormat().formatCount,
|
|
146
|
+
workspaces: useI18nWorkspaces(),
|
|
147
|
+
translations: useWorkspaceFlat(),
|
|
148
|
+
current,
|
|
149
|
+
canManage,
|
|
150
|
+
nativeName: useLocaleNames().nativeName,
|
|
151
|
+
isAddOpen: useDmsState<boolean>('dms-lang-add-language-open', () => false),
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
addLanguage: () => addLanguage(context),
|
|
155
|
+
removeLanguage: (code: string, afterRemove?: () => Promise<unknown>) =>
|
|
156
|
+
removeLanguage(context, code, afterRemove),
|
|
157
|
+
makeBase: (code: string) => makeBase(context, code),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue'
|
|
2
|
+
import { useDmsRouter } from '#dms/frontend-module'
|
|
3
|
+
import type { FlatTranslationRow, FlatTranslations } from '../../types/lang'
|
|
4
|
+
|
|
5
|
+
export type QueueMode = 'missing' | 'issues' | 'all'
|
|
6
|
+
|
|
7
|
+
export interface NamespaceProgress {
|
|
8
|
+
namespace: string
|
|
9
|
+
coverage: number
|
|
10
|
+
missing: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Whether a row passes a check (fits a mode, holds a draft…). */
|
|
14
|
+
type RowCheck = (row: FlatTranslationRow) => boolean
|
|
15
|
+
|
|
16
|
+
type RowOrder = (left: FlatTranslationRow, right: FlatTranslationRow) => number
|
|
17
|
+
|
|
18
|
+
type NamespaceCheck = (namespace: string) => boolean
|
|
19
|
+
|
|
20
|
+
/** The checks a language page sorts its rows with. */
|
|
21
|
+
interface RowChecks {
|
|
22
|
+
isMissing: RowCheck
|
|
23
|
+
isOutdated: RowCheck
|
|
24
|
+
hasIssue: RowCheck
|
|
25
|
+
modes: Record<QueueMode, RowCheck>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const QUEUE_MODES: QueueMode[] = ['missing', 'issues', 'all']
|
|
29
|
+
const DEFAULT_MODE: QueueMode = 'missing'
|
|
30
|
+
|
|
31
|
+
function parseMode(value: string | undefined): QueueMode {
|
|
32
|
+
return QUEUE_MODES.find((mode) => mode === value) ?? DEFAULT_MODE
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The text a draft saves: nothing when it is only spaces, else as typed. The
|
|
37
|
+
* spaces around it are kept (and warned about), as in the matrix and the panel.
|
|
38
|
+
*/
|
|
39
|
+
export function normalizeDraft(draft: string): string {
|
|
40
|
+
return draft.trim() ? draft : ''
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The queue's part of the page URL (`?mode=`, `?namespace=`, `?key=`), read
|
|
45
|
+
* from the route and written back with `replaceQuery`.
|
|
46
|
+
*/
|
|
47
|
+
function useQueueQuery() {
|
|
48
|
+
const { route } = useWorkspaceRoute()
|
|
49
|
+
const router = useDmsRouter()
|
|
50
|
+
|
|
51
|
+
/** Replaces the given parameters of the page URL (an empty one is removed). */
|
|
52
|
+
function replaceQuery(change: PageQuery): Promise<void> {
|
|
53
|
+
if (import.meta.env.SSR) return Promise.resolve()
|
|
54
|
+
return router.replace(
|
|
55
|
+
linkWithQuery(route.path, { ...route.query, ...change }),
|
|
56
|
+
{ preserveScroll: true },
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
mode: computed(() => parseMode(route.query.mode)),
|
|
62
|
+
namespace: computed(() => route.query.namespace ?? ''),
|
|
63
|
+
replaceQuery,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function rowChecks(locale: ComputedRef<string>): RowChecks {
|
|
68
|
+
const isMissing = (row: FlatTranslationRow) =>
|
|
69
|
+
isRowValueMissing(row, locale.value)
|
|
70
|
+
const isOutdated = (row: FlatTranslationRow) =>
|
|
71
|
+
row.outdated?.includes(locale.value) ?? false
|
|
72
|
+
const hasIssue = (row: FlatTranslationRow) => needsReview(row, locale.value)
|
|
73
|
+
return {
|
|
74
|
+
isMissing,
|
|
75
|
+
isOutdated,
|
|
76
|
+
hasIssue,
|
|
77
|
+
modes: { missing: isMissing, issues: hasIssue, all: () => true },
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function progressOf(flat: FlatTranslations, locale: string) {
|
|
82
|
+
return namespaceCoverage(flat.rows, [locale])
|
|
83
|
+
.map((entry) => ({
|
|
84
|
+
namespace: entry.namespace,
|
|
85
|
+
coverage: entry.coverage[locale] ?? 0,
|
|
86
|
+
missing: entry.missing[locale] ?? 0,
|
|
87
|
+
}))
|
|
88
|
+
.sort(
|
|
89
|
+
(left, right) =>
|
|
90
|
+
left.coverage - right.coverage ||
|
|
91
|
+
left.namespace.localeCompare(right.namespace),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The namespaces of the language, least complete first, and the row order it gives. */
|
|
96
|
+
function useNamespaceProgress(
|
|
97
|
+
flat: ComputedRef<FlatTranslations>,
|
|
98
|
+
locale: ComputedRef<string>,
|
|
99
|
+
) {
|
|
100
|
+
const namespaceProgress = computed<NamespaceProgress[]>(() =>
|
|
101
|
+
progressOf(flat.value, locale.value),
|
|
102
|
+
)
|
|
103
|
+
const namespaceRank = computed(
|
|
104
|
+
() =>
|
|
105
|
+
new Map(
|
|
106
|
+
namespaceProgress.value.map((entry, index) => [entry.namespace, index]),
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
const compareRows: RowOrder = (left, right) => {
|
|
110
|
+
const rankOf = (row: FlatTranslationRow) =>
|
|
111
|
+
namespaceRank.value.get(namespaceOf(row.key)) ?? 0
|
|
112
|
+
return rankOf(left) - rankOf(right) || left.key.localeCompare(right.key)
|
|
113
|
+
}
|
|
114
|
+
const hasNamespace = (name: string) => namespaceRank.value.has(name)
|
|
115
|
+
return { namespaceProgress, hasNamespace, compareRows }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The mode and the namespace, read from the URL and written back to it. A
|
|
120
|
+
* namespace the language does not have is taken out of the URL.
|
|
121
|
+
*/
|
|
122
|
+
function useQueueScope(hasNamespace: NamespaceCheck) {
|
|
123
|
+
const query = useQueueQuery()
|
|
124
|
+
const { isLoaded } = useWorkspaceFlat()
|
|
125
|
+
const namespace = computed<string>({
|
|
126
|
+
get: () =>
|
|
127
|
+
hasNamespace(query.namespace.value) ? query.namespace.value : '',
|
|
128
|
+
set: (value) => void query.replaceQuery({ namespace: value }),
|
|
129
|
+
})
|
|
130
|
+
const mode = computed<QueueMode>({
|
|
131
|
+
get: () => query.mode.value,
|
|
132
|
+
set: (value) =>
|
|
133
|
+
void query.replaceQuery({
|
|
134
|
+
mode: value === DEFAULT_MODE ? undefined : value,
|
|
135
|
+
}),
|
|
136
|
+
})
|
|
137
|
+
watch(
|
|
138
|
+
[query.namespace, isLoaded],
|
|
139
|
+
([raw, loaded]) => {
|
|
140
|
+
if (loaded && raw && !hasNamespace(raw))
|
|
141
|
+
void query.replaceQuery({ namespace: undefined })
|
|
142
|
+
},
|
|
143
|
+
{ immediate: true },
|
|
144
|
+
)
|
|
145
|
+
return { mode, namespace, replaceQuery: query.replaceQuery }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function queueFacts(
|
|
149
|
+
flat: ComputedRef<FlatTranslations>,
|
|
150
|
+
locale: ComputedRef<string>,
|
|
151
|
+
checks: RowChecks,
|
|
152
|
+
scoped: ComputedRef<FlatTranslationRow[]>,
|
|
153
|
+
) {
|
|
154
|
+
const missingOf = (code: string) => flat.value.localeMissing[code] ?? 0
|
|
155
|
+
return {
|
|
156
|
+
isBase: computed(() => locale.value === flat.value.defaultLocale),
|
|
157
|
+
/** The languages to translate besides this one, the least complete first. */
|
|
158
|
+
otherLanguages: computed(() =>
|
|
159
|
+
flat.value.locales
|
|
160
|
+
.filter(
|
|
161
|
+
(code) => code !== flat.value.defaultLocale && code !== locale.value,
|
|
162
|
+
)
|
|
163
|
+
.sort((left, right) => missingOf(right) - missingOf(left)),
|
|
164
|
+
),
|
|
165
|
+
exists: computed(() => flat.value.locales.includes(locale.value)),
|
|
166
|
+
counts: computed(() => ({
|
|
167
|
+
missing: scoped.value.filter(checks.isMissing).length,
|
|
168
|
+
issues: scoped.value.filter(checks.hasIssue).length,
|
|
169
|
+
all: scoped.value.length,
|
|
170
|
+
})),
|
|
171
|
+
missingTotal: computed(
|
|
172
|
+
() => flat.value.rows.filter(checks.isMissing).length,
|
|
173
|
+
),
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The keys of a pass: the queue, plus the rows `keep` holds whatever the mode
|
|
179
|
+
* and the namespace, in the order of the queue.
|
|
180
|
+
*/
|
|
181
|
+
function passOf(
|
|
182
|
+
rows: FlatTranslationRow[],
|
|
183
|
+
queue: FlatTranslationRow[],
|
|
184
|
+
keep: RowCheck,
|
|
185
|
+
compare: RowOrder,
|
|
186
|
+
): string[] {
|
|
187
|
+
const inQueue = new Set(queue)
|
|
188
|
+
return rows
|
|
189
|
+
.filter((row) => inQueue.has(row) || keep(row))
|
|
190
|
+
.sort(compare)
|
|
191
|
+
.map((row) => row.key)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The language a Language page works on (`?locale=`) and the keys its queue
|
|
196
|
+
* walks through, shared by the queue and its side panels. The mode and the
|
|
197
|
+
* namespace live in the URL (`?mode=`, `?namespace=`): a link or a refresh
|
|
198
|
+
* lands on the same queue, and another language starts unscoped.
|
|
199
|
+
*/
|
|
200
|
+
export const useLanguageQueue = () => {
|
|
201
|
+
const { route } = useWorkspaceRoute()
|
|
202
|
+
const { flat } = useWorkspaceFlat()
|
|
203
|
+
const locale = computed(() => route.query.locale ?? '')
|
|
204
|
+
const checks = rowChecks(locale)
|
|
205
|
+
const order = useNamespaceProgress(flat, locale)
|
|
206
|
+
const scope = useQueueScope(order.hasNamespace)
|
|
207
|
+
const inScope = (row: FlatTranslationRow) =>
|
|
208
|
+
!scope.namespace.value || namespaceOf(row.key) === scope.namespace.value
|
|
209
|
+
const scoped = computed(() => flat.value.rows.filter(inScope))
|
|
210
|
+
const matchesMode = (row: FlatTranslationRow) =>
|
|
211
|
+
checks.modes[scope.mode.value](row)
|
|
212
|
+
const queue = computed(() =>
|
|
213
|
+
scoped.value.filter(matchesMode).sort(order.compareRows),
|
|
214
|
+
)
|
|
215
|
+
return {
|
|
216
|
+
...queueFacts(flat, locale, checks, scoped),
|
|
217
|
+
...checks,
|
|
218
|
+
locale,
|
|
219
|
+
baseLocale: computed(() => flat.value.defaultLocale),
|
|
220
|
+
mode: scope.mode,
|
|
221
|
+
namespace: scope.namespace,
|
|
222
|
+
namespaceProgress: order.namespaceProgress,
|
|
223
|
+
queue,
|
|
224
|
+
matchesMode,
|
|
225
|
+
passOf: (keep: RowCheck) =>
|
|
226
|
+
passOf(flat.value.rows, queue.value, keep, order.compareRows),
|
|
227
|
+
/** Writes the key the queue stands on in the page URL. */
|
|
228
|
+
syncKey: (key: string) => scope.replaceQuery({ key }),
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type LanguageQueue = ReturnType<typeof useLanguageQueue>
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SEARCHABLE_LANGUAGE_CODES,
|
|
3
|
+
SUGGESTED_LANGUAGE_CODES,
|
|
4
|
+
languageOf,
|
|
5
|
+
lastSubtag,
|
|
6
|
+
searchLanguages,
|
|
7
|
+
sharesLanguage,
|
|
8
|
+
typedLocaleCode,
|
|
9
|
+
type LanguageOption,
|
|
10
|
+
} from '../../utils/languages'
|
|
11
|
+
import { boundedCache } from '../../utils/boundedCache'
|
|
12
|
+
|
|
13
|
+
/** Which names a formatter gives: the language alone, or with its region and script. */
|
|
14
|
+
type DisplayKind = 'language' | 'full'
|
|
15
|
+
|
|
16
|
+
/** A language of the interface, as vue-i18n lists them. */
|
|
17
|
+
interface InterfaceLocale {
|
|
18
|
+
code: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ENGLISH = 'en'
|
|
22
|
+
const TILE_REGION_SEPARATOR = '-'
|
|
23
|
+
/** Formatters and options kept: a picker's languages, with room for the codes typed. */
|
|
24
|
+
const CACHE_LIMIT = 500
|
|
25
|
+
|
|
26
|
+
const DISPLAY_OPTIONS: Record<DisplayKind, Intl.DisplayNamesOptions> = {
|
|
27
|
+
language: { type: 'language', fallback: 'none' },
|
|
28
|
+
full: { type: 'language', fallback: 'none', languageDisplay: 'standard' },
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const formatters = boundedCache<Intl.DisplayNames | null>(CACHE_LIMIT)
|
|
32
|
+
const optionCache = boundedCache<LanguageOption>(CACHE_LIMIT)
|
|
33
|
+
|
|
34
|
+
/** One formatter per language and kind of name; none for a language the browser refuses. */
|
|
35
|
+
function formatterOf(inLocale: string, kind: DisplayKind) {
|
|
36
|
+
const id = `${kind}:${inLocale}`
|
|
37
|
+
if (formatters.has(id)) return formatters.get(id) ?? null
|
|
38
|
+
try {
|
|
39
|
+
return formatters.set(
|
|
40
|
+
id,
|
|
41
|
+
new Intl.DisplayNames([inLocale], DISPLAY_OPTIONS[kind]),
|
|
42
|
+
)
|
|
43
|
+
} catch {
|
|
44
|
+
return formatters.set(id, null)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function displayName(
|
|
49
|
+
code: string,
|
|
50
|
+
inLocale: string,
|
|
51
|
+
kind: DisplayKind = 'language',
|
|
52
|
+
): string | undefined {
|
|
53
|
+
try {
|
|
54
|
+
return formatterOf(inLocale, kind)?.of(code)
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function capitalize(text: string, locale: string): string {
|
|
61
|
+
try {
|
|
62
|
+
return text.charAt(0).toLocaleUpperCase(locale) + text.slice(1)
|
|
63
|
+
} catch {
|
|
64
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function named(name: string | undefined, locale: string, code: string) {
|
|
69
|
+
return name ? capitalize(name, locale) : code
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The language as its speakers write it ("Italiano" for it-IT). */
|
|
73
|
+
function nativeName(code: string): string {
|
|
74
|
+
const name = displayName(languageOf(code), code) ?? displayName(code, code)
|
|
75
|
+
return named(name, code, code)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The language and its region or script as its speakers write them ("English (United Kingdom)"). */
|
|
79
|
+
function fullName(code: string): string {
|
|
80
|
+
const name = displayName(code, code, 'full')
|
|
81
|
+
return name ? named(name, code, code) : nativeName(code)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The language and its region in the interface language ("Portuguese (Brazil)"). */
|
|
85
|
+
function fullLocalName(code: string, ui: string): string {
|
|
86
|
+
const name =
|
|
87
|
+
displayName(code, ui, 'full') ?? displayName(languageOf(code), ui)
|
|
88
|
+
return named(name, ui, code)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Every name a picker finds a language by: native, English and in each
|
|
93
|
+
* language of the interface ("Royaume-Uni" finds en-GB in English too).
|
|
94
|
+
*/
|
|
95
|
+
function searchNames(code: string, uiLocales: string[]): string[] {
|
|
96
|
+
const [ui = ENGLISH] = uiLocales
|
|
97
|
+
const names = [ENGLISH, ...uiLocales].map((inLocale) =>
|
|
98
|
+
named(displayName(code, inLocale, 'full'), inLocale, code),
|
|
99
|
+
)
|
|
100
|
+
const own = [fullName(code), nativeName(code), fullLocalName(code, ui)]
|
|
101
|
+
return [...new Set([...own, ...names])]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The letters of a code tile: the language ("PT"), with the last subtag when another language of `codes` shares it ("PT-BR"). */
|
|
105
|
+
function tileOf(code: string, codes: string[] = []): string {
|
|
106
|
+
const language = languageOf(code)
|
|
107
|
+
const variant = lastSubtag(code)
|
|
108
|
+
if (!sharesLanguage(code, codes) || variant === language)
|
|
109
|
+
return language.toUpperCase()
|
|
110
|
+
return `${language}${TILE_REGION_SEPARATOR}${variant}`.toUpperCase()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function languageOption(code: string, uiLocales: string[]): LanguageOption {
|
|
114
|
+
const [ui = ENGLISH] = uiLocales
|
|
115
|
+
const id = `${uiLocales.join()}:${code}`
|
|
116
|
+
return (
|
|
117
|
+
optionCache.get(id) ??
|
|
118
|
+
optionCache.set(id, {
|
|
119
|
+
code,
|
|
120
|
+
name: fullName(code),
|
|
121
|
+
localName: fullLocalName(code, ui),
|
|
122
|
+
names: searchNames(code, uiLocales),
|
|
123
|
+
isUnknown: displayName(languageOf(code), ENGLISH) === undefined,
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The languages a picker offers for a search, best first: the suggested
|
|
130
|
+
* ones (and, once something is typed, the regional variants a search
|
|
131
|
+
* finds), plus the code the search spells when it is a valid BCP 47 code
|
|
132
|
+
* missing from them (de-CH-1996, es-419).
|
|
133
|
+
*/
|
|
134
|
+
function findLanguages(search: string, uiLocales: string[]): LanguageOption[] {
|
|
135
|
+
const offered = search.trim()
|
|
136
|
+
? [...SUGGESTED_LANGUAGE_CODES, ...SEARCHABLE_LANGUAGE_CODES]
|
|
137
|
+
: SUGGESTED_LANGUAGE_CODES
|
|
138
|
+
const typed = typedLocaleCode(search)
|
|
139
|
+
const all = typed && !offered.includes(typed) ? [...offered, typed] : offered
|
|
140
|
+
return searchLanguages(
|
|
141
|
+
all.map((code) => languageOption(code, uiLocales)),
|
|
142
|
+
search,
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Names and code tiles of languages, without flags: a language is not a country. */
|
|
147
|
+
export const useLocaleNames = () => {
|
|
148
|
+
const { locale, locales } = useI18n()
|
|
149
|
+
/** The interface language first, then every other one ("en-GB", "fr-FR"). */
|
|
150
|
+
const uiLocales = () => [
|
|
151
|
+
locale.value,
|
|
152
|
+
...locales.value.map((entry: string | InterfaceLocale) =>
|
|
153
|
+
typeof entry === 'string' ? entry : entry.code,
|
|
154
|
+
),
|
|
155
|
+
]
|
|
156
|
+
return {
|
|
157
|
+
nativeName,
|
|
158
|
+
fullName,
|
|
159
|
+
tileOf,
|
|
160
|
+
/** The native name, with the region only when another language of `codes` shares it. */
|
|
161
|
+
nameAmong: (code: string, codes: string[]) =>
|
|
162
|
+
sharesLanguage(code, codes) ? fullName(code) : nativeName(code),
|
|
163
|
+
languageOption: (code: string) => languageOption(code, uiLocales()),
|
|
164
|
+
findLanguages: (search: string) => findLanguages(search, uiLocales()),
|
|
165
|
+
}
|
|
166
|
+
}
|