forked from Mirrors/elk
Compare commits
2 commits
main
...
feat/inclu
Author | SHA1 | Date | |
---|---|---|---|
|
410965b3c8 | ||
|
863eab1598 |
7 changed files with 82 additions and 7 deletions
|
@ -13,6 +13,7 @@ export interface WellnessSettings {
|
||||||
hideBoostCount: boolean
|
hideBoostCount: boolean
|
||||||
hideFavoriteCount: boolean
|
hideFavoriteCount: boolean
|
||||||
hideFollowerCount: boolean
|
hideFollowerCount: boolean
|
||||||
|
useInclusiveWriting: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserSettings {
|
export interface UserSettings {
|
||||||
|
@ -38,6 +39,7 @@ export const DEFAULT_WELLNESS_SETTINGS: WellnessSettings = {
|
||||||
hideBoostCount: false,
|
hideBoostCount: false,
|
||||||
hideFavoriteCount: false,
|
hideFavoriteCount: false,
|
||||||
hideFollowerCount: false,
|
hideFollowerCount: false,
|
||||||
|
useInclusiveWriting: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
|
export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
|
||||||
|
|
|
@ -3,13 +3,19 @@ import type { DateTimeFormats, NumberFormats, PluralizationRule, PluralizationRu
|
||||||
|
|
||||||
import type { LocaleObject } from '#i18n'
|
import type { LocaleObject } from '#i18n'
|
||||||
|
|
||||||
interface LocaleObjectData extends LocaleObject {
|
export interface InclusiveLocaleKey {
|
||||||
|
adoptInclusiveWriting?: boolean
|
||||||
|
inclusiveTransform?: (term: string) => string
|
||||||
|
}
|
||||||
|
declare module '#i18n' {
|
||||||
|
interface LocaleObject extends InclusiveLocaleKey {
|
||||||
numberFormats?: NumberFormats
|
numberFormats?: NumberFormats
|
||||||
dateTimeFormats?: DateTimeFormats
|
dateTimeFormats?: DateTimeFormats
|
||||||
pluralRule?: PluralizationRule
|
pluralRule?: PluralizationRule
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const locales: LocaleObjectData[] = [
|
export const locales: LocaleObject[] = [
|
||||||
{
|
{
|
||||||
code: 'en-US',
|
code: 'en-US',
|
||||||
file: 'en-US.json',
|
file: 'en-US.json',
|
||||||
|
@ -29,7 +35,7 @@ const locales: LocaleObjectData[] = [
|
||||||
const name = new Intl.PluralRules('ar-EG').select(choice)
|
const name = new Intl.PluralRules('ar-EG').select(choice)
|
||||||
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
||||||
},
|
},
|
||||||
} satisfies LocaleObjectData),
|
} satisfies LocaleObject),
|
||||||
{
|
{
|
||||||
code: 'de-DE',
|
code: 'de-DE',
|
||||||
file: 'de-DE.json',
|
file: 'de-DE.json',
|
||||||
|
@ -64,6 +70,10 @@ const locales: LocaleObjectData[] = [
|
||||||
code: 'fr-FR',
|
code: 'fr-FR',
|
||||||
file: 'fr-FR.json',
|
file: 'fr-FR.json',
|
||||||
name: 'Français',
|
name: 'Français',
|
||||||
|
adoptInclusiveWriting: true,
|
||||||
|
inclusiveTransform(term: string) {
|
||||||
|
return term.replaceAll(/·\w+·?/g, '')
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'uk-UA',
|
code: 'uk-UA',
|
||||||
|
@ -87,6 +97,16 @@ const locales: LocaleObjectData[] = [
|
||||||
file: 'tr-TR.json',
|
file: 'tr-TR.json',
|
||||||
name: 'Türkçe',
|
name: 'Türkçe',
|
||||||
},
|
},
|
||||||
|
({
|
||||||
|
code: 'ar-EG',
|
||||||
|
file: 'ar-EG.json',
|
||||||
|
name: 'العربية',
|
||||||
|
dir: 'rtl',
|
||||||
|
pluralRule: (choice: number) => {
|
||||||
|
const name = new Intl.PluralRules('ar-EG').select(choice)
|
||||||
|
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
||||||
|
},
|
||||||
|
} satisfies LocaleObject),
|
||||||
].sort((a, b) => a.code.localeCompare(b.code))
|
].sort((a, b) => a.code.localeCompare(b.code))
|
||||||
|
|
||||||
const datetimeFormats = Object.values(locales).reduce((acc, data) => {
|
const datetimeFormats = Object.values(locales).reduce((acc, data) => {
|
||||||
|
|
|
@ -273,6 +273,7 @@
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"display_language": "Display Language",
|
"display_language": "Display Language",
|
||||||
|
"inclusive": "Use epicene terms (median point)",
|
||||||
"label": "Language"
|
"label": "Language"
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
|
|
|
@ -268,6 +268,7 @@
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"display_language": "Langue d'affichage",
|
"display_language": "Langue d'affichage",
|
||||||
|
"inclusive": "Utiliser l'écriture épicène (point médiant)",
|
||||||
"label": "Langue"
|
"label": "Langue"
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
|
|
41
modules/legacy-language.ts
Normal file
41
modules/legacy-language.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { readFile, writeFile } from 'node:fs/promises'
|
||||||
|
import { defineNuxtModule, useNuxt } from '@nuxt/kit'
|
||||||
|
import type { InclusiveLocaleKey } from '../config/i18n'
|
||||||
|
import { locales } from '../config/i18n'
|
||||||
|
import type { LocaleObject } from '#i18n'
|
||||||
|
|
||||||
|
type LocaleObjectWithRawFile = Omit<LocaleObject, 'file'> & {
|
||||||
|
file: Buffer
|
||||||
|
inclusiveTransform: InclusiveLocaleKey['inclusiveTransform']
|
||||||
|
}
|
||||||
|
|
||||||
|
function languageTransformation(locale: LocaleObjectWithRawFile) {
|
||||||
|
return locale.inclusiveTransform!(locale.file.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineNuxtModule({
|
||||||
|
meta: { name: 'legacy-language' },
|
||||||
|
setup() {
|
||||||
|
const nuxt = useNuxt()
|
||||||
|
nuxt.hook('nitro:init', (nitro) => {
|
||||||
|
const dir = `${nitro.options.output.dir}/public`
|
||||||
|
nitro.hooks.hook('compiled', async () => {
|
||||||
|
// spot language which needs dot-syntax free alternative
|
||||||
|
const inclusiveSyntaxLanguages = locales.filter(locale => locale.adoptInclusiveWriting && !!locale.inclusiveTransform && locale.file && locale.code).map(async locale => ({
|
||||||
|
...locale,
|
||||||
|
file: await readFile(`locales/${locale.file!}`),
|
||||||
|
}))
|
||||||
|
|
||||||
|
const localesFiles = await Promise.all(inclusiveSyntaxLanguages) as LocaleObjectWithRawFile[]
|
||||||
|
const transformedFiles = localesFiles
|
||||||
|
.map(locale => ({ ...locale, file: languageTransformation(locale) }))
|
||||||
|
.map(async (locale) => {
|
||||||
|
// @ts-expect-error locales with raw file need right types
|
||||||
|
await writeFile(`${dir}/${locale.code}-ninc.json`, locale.file)
|
||||||
|
})
|
||||||
|
|
||||||
|
Promise.all(transformedFiles)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
|
@ -31,6 +31,7 @@ export default defineNuxtConfig({
|
||||||
'~/modules/tauri/index',
|
'~/modules/tauri/index',
|
||||||
'~/modules/pwa/index', // change to '@vite-pwa/nuxt' once released and remove pwa module
|
'~/modules/pwa/index', // change to '@vite-pwa/nuxt' once released and remove pwa module
|
||||||
'~/modules/stale-dep',
|
'~/modules/stale-dep',
|
||||||
|
'~/modules/legacy-language',
|
||||||
],
|
],
|
||||||
experimental: {
|
experimental: {
|
||||||
payloadExtraction: false,
|
payloadExtraction: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { t } = useI18n()
|
const { t, localeProperties } = useI18n()
|
||||||
|
|
||||||
useHeadFixed({
|
useHeadFixed({
|
||||||
title: () => `${t('settings.language.label')} | ${t('nav.settings')}`,
|
title: () => `${t('settings.language.label')} | ${t('nav.settings')}`,
|
||||||
|
@ -18,6 +18,15 @@ useHeadFixed({
|
||||||
<p font-medium>{{ $t('settings.language.display_language') }}</p>
|
<p font-medium>{{ $t('settings.language.display_language') }}</p>
|
||||||
<SettingsLanguage select-settings />
|
<SettingsLanguage select-settings />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<SettingsToggleItem
|
||||||
|
v-if="localeProperties.adoptInclusiveWriting"
|
||||||
|
:checked="getWellnessSetting('useInclusiveWriting')"
|
||||||
|
m-t
|
||||||
|
@click="toggleWellnessSetting('useInclusiveWriting')"
|
||||||
|
>
|
||||||
|
{{ $t('settings.language.inclusive') }}
|
||||||
|
</SettingsToggleItem>
|
||||||
</div>
|
</div>
|
||||||
</MainContent>
|
</MainContent>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in a new issue