Skip to content

Commit 2f12994

Browse files
authored
Move constant to fix translations (#591)
* Move constant to fix translations * Add more alphabets to characters allowed for path * Fix lint issue * Add Korean letters (Jamo) to allowed list as normalization decomposes syllables (Hagul) to letters
1 parent 587d8db commit 2f12994

1 file changed

Lines changed: 45 additions & 29 deletions

File tree

‎src/lib/generate-site-name.ts‎

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { __ } from '@wordpress/i18n';
22

3-
const siteNames = [
4-
__( 'My Bold Website' ),
5-
__( 'My Bright Website' ),
6-
__( 'My Blissful Website' ),
7-
__( 'My Calm Website' ),
8-
__( 'My Cool Website' ),
9-
__( 'My Dreamy Website' ),
10-
__( 'My Elite Website' ),
11-
__( 'My Fresh Website' ),
12-
__( 'My Glowing Website' ),
13-
__( 'My Happy Website' ),
14-
__( 'My Joyful Website' ),
15-
__( 'My Noble Website' ),
16-
__( 'My Pure Website' ),
17-
__( 'My Peak Website' ),
18-
__( 'My Prime Website' ),
19-
__( 'My Serene Website' ),
20-
__( 'My Shiny Website' ),
21-
__( 'My Sparkly Website' ),
22-
__( 'My Swift Website' ),
23-
__( 'My True Website' ),
24-
];
25-
263
export function generateSiteName( usedSiteNames: string[] ): string {
4+
const siteNames = [
5+
__( 'My Bold Website' ),
6+
__( 'My Bright Website' ),
7+
__( 'My Blissful Website' ),
8+
__( 'My Calm Website' ),
9+
__( 'My Cool Website' ),
10+
__( 'My Dreamy Website' ),
11+
__( 'My Elite Website' ),
12+
__( 'My Fresh Website' ),
13+
__( 'My Glowing Website' ),
14+
__( 'My Happy Website' ),
15+
__( 'My Joyful Website' ),
16+
__( 'My Noble Website' ),
17+
__( 'My Pure Website' ),
18+
__( 'My Peak Website' ),
19+
__( 'My Prime Website' ),
20+
__( 'My Serene Website' ),
21+
__( 'My Shiny Website' ),
22+
__( 'My Sparkly Website' ),
23+
__( 'My Swift Website' ),
24+
__( 'My True Website' ),
25+
];
2726
let proposedName = __( 'My WordPress Website' );
2827
let tryCount = 0;
2928

@@ -36,14 +35,31 @@ export function generateSiteName( usedSiteNames: string[] ): string {
3635
}
3736

3837
export const sanitizeFolderName = ( filename: string ) => {
38+
const LATIN = 'a-z';
39+
const CYRILLIC = 'а-яё';
40+
const ARABIC = '\\u0600-\\u06FF';
41+
const HEBREW = '\\u0590-\\u05FF';
42+
const CHINESE = '\\u4e00-\\u9fa5';
43+
const JAPANESE_HIRAGANA = '\\u3040-\\u309F';
44+
const JAPANESE_KATAKANA = '\\u30A0-\\u30FF';
45+
const KOREAN_HANGUL = '\\uAC00-\\uD7AF';
46+
const KOREAN_JAMO = '\\u1100-\\u11FF'; // Hangul syllables are decomposed to Jamo letters
47+
const NUMBERS = '0-9';
48+
const WHITELISTED_SYMBOLS = '_\\- '; // Allow underscore, hyphen, and space
49+
50+
const ALLOWED_CHARS = new RegExp(
51+
`[^${ LATIN }${ NUMBERS }${ CYRILLIC }${ ARABIC }${ HEBREW }${ CHINESE }${ JAPANESE_HIRAGANA }${ JAPANESE_KATAKANA }${ KOREAN_HANGUL }${ KOREAN_JAMO }${ WHITELISTED_SYMBOLS }]`,
52+
'gi'
53+
);
54+
3955
return String( filename )
40-
.replace( /ł/g, 'l' )
41-
.replace( /Ł/g, 'L' )
56+
.replace( /ł/g, 'l' ) // Polish ł to l
57+
.replace( /Ł/g, 'L' ) // Polish Ł to L
4258
.normalize( 'NFKD' )
43-
.replace( /[\u0300-\u036f]/g, '' )
59+
.replace( /[\u0300-\u036f]/g, '' ) // Remove diacritics
4460
.toLowerCase()
45-
.replace( /[^a-z0-9 -]/g, '' )
61+
.replace( ALLOWED_CHARS, '' )
4662
.trim()
47-
.replace( /\s+/g, '-' )
48-
.replace( /-+/g, '-' );
63+
.replace( /\s+/g, '-' ) // Replace spaces with hyphens
64+
.replace( /-+/g, '-' ); // Replace multiple hyphens with a single one
4965
};

0 commit comments

Comments
 (0)