Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3973670

Browse files
authored
Add an option to make text longer in pseudolocalization (#926)
1 parent 3550c2e commit 3973670

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/devtools/plugin.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ export function registerFluentVueDevtools(app: App, options: ResolvedOptions, fl
103103
description: 'Enable pseudolocalization',
104104
type: 'boolean',
105105
},
106+
pseudoLength: {
107+
defaultValue: 1,
108+
label: 'Length',
109+
description: 'Pseudolocalization length',
110+
type: 'choice',
111+
options: [
112+
{ label: '100%', value: 1 },
113+
{ label: '125%', value: 1.25 },
114+
{ label: '150%', value: 1.5 },
115+
{ label: '175%', value: 1.75 },
116+
{ label: '200%', value: 2 },
117+
{ label: '250%', value: 2.5 },
118+
{ label: '300%', value: 3 },
119+
],
120+
},
106121
pseudoAccents: {
107122
defaultValue: true,
108123
label: 'Accents',
@@ -281,15 +296,17 @@ export function registerFluentVueDevtools(app: App, options: ResolvedOptions, fl
281296
function handleSettingsChange(settings: {
282297
pseudoEnable: boolean
283298
pseudoType: string
299+
pseudoLength: number
284300
pseudoPrefix: string
285301
pseudoSuffix: string
286302
pseudoAccents: boolean
287303
}) {
288304
if (settings.pseudoEnable) {
289305
currentPseudoLocalize = str => pseudoLocalize(str, {
290-
prefix: settings.pseudoPrefix ?? undefined,
291-
suffix: settings.pseudoSuffix ?? undefined,
306+
prefix: settings.pseudoPrefix ?? '',
307+
suffix: settings.pseudoSuffix ?? '',
292308
accents: settings.pseudoAccents ?? false,
309+
expand: settings.pseudoLength ?? 1,
293310
})
294311
}
295312
else {

src/devtools/pseudoLocalize.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@ interface PseudolocalizationOptions {
55
prefix: string
66
suffix: string
77
accents: boolean
8+
expand: number
89
}
910

1011
export default function pseudoLocalize(str: string, options: PseudolocalizationOptions): string {
11-
let finalString = ''
12-
13-
if (options.prefix)
14-
finalString += options.prefix
15-
16-
for (let i = 0; i < str.length; i++) {
17-
const character = str[i]
12+
let pseudoString = ''
13+
for (let i = 0; i < str.length * options.expand; i++) {
14+
const index = Math.floor(i / options.expand)
15+
const character = str[index]
1816
const convertedCharacter = options.accents
1917
? ACCENTED_ASCII[ASCII.indexOf(character)] ?? character
2018
: character
2119

22-
finalString += convertedCharacter
20+
pseudoString += convertedCharacter
2321
}
2422

25-
if (options.suffix)
26-
finalString += options.suffix
27-
28-
return finalString
23+
return options.prefix + pseudoString + options.suffix
2924
}

0 commit comments

Comments
 (0)