1
1
<?php
2
+
2
3
/**
3
4
* @file classes/dev/ComposerScript.php
4
5
*
@@ -40,24 +41,24 @@ public static function isoFileCheck(): void
40
41
public static function weblateFilesDownload (): void
41
42
{
42
43
try {
43
- $ dirPath = dirname (__FILE__ , 3 ) . " /lib/weblateLanguages " ;
44
- $ langFilePath = "$ dirPath/languages.json " ;
44
+ $ dirPath = dirname (__FILE__ , 3 ) . ' /lib/weblateLanguages ' ;
45
+ $ langFilePath = "{ $ dirPath} /languages.json " ;
45
46
$ urlCsv = 'https://raw.githubusercontent.com/WeblateOrg/language-data/main/languages.csv ' ;
46
47
47
48
if (!is_dir ($ dirPath )) {
48
49
mkdir ($ dirPath );
49
50
}
50
51
51
52
$ streamContext = stream_context_create (['http ' => ['method ' => 'HEAD ' ]]);
52
- $ languagesCsv = !preg_match ('/200 OK/ ' , get_headers ($ urlCsv , false , $ streamContext )[0 ] ?? "" ) ?: file ($ urlCsv , FILE_SKIP_EMPTY_LINES );
53
+ $ languagesCsv = !preg_match ('/200 OK/ ' , get_headers ($ urlCsv , false , $ streamContext )[0 ] ?? '' ) ?: file ($ urlCsv , FILE_SKIP_EMPTY_LINES );
53
54
if (!is_array ($ languagesCsv ) || !$ languagesCsv ) {
54
55
throw new Exception (__METHOD__ . " : The Weblate file 'languages.csv' cannot be downloaded ! " );
55
56
}
56
57
57
58
array_shift ($ languagesCsv );
58
59
$ languages = [];
59
- foreach ($ languagesCsv as $ languageCsv ) {
60
- $ localeAndName = str_getcsv ($ languageCsv , " , " );
60
+ foreach ($ languagesCsv as $ languageCsv ) {
61
+ $ localeAndName = str_getcsv ($ languageCsv , ' , ' , escape: '\\' );
61
62
if (isset ($ localeAndName [0 ], $ localeAndName [1 ]) && preg_match ('/^[\w@-]{2,50}$/ ' , $ localeAndName [0 ])) {
62
63
$ displayName = locale_get_display_name ($ localeAndName [0 ], 'en ' );
63
64
$ languages [$ localeAndName [0 ]] = (($ displayName && $ displayName !== $ localeAndName [0 ]) ? $ displayName : $ localeAndName [1 ]);
@@ -66,7 +67,7 @@ public static function weblateFilesDownload(): void
66
67
67
68
$ languagesJson = json_encode ($ languages , JSON_THROW_ON_ERROR );
68
69
if (!$ languagesJson || !file_put_contents ($ langFilePath , $ languagesJson )) {
69
- throw new Exception (__METHOD__ . " : Json file empty, or save unsuccessful: $ langFilePath ! " );
70
+ throw new Exception (__METHOD__ . " : Json file empty, or save unsuccessful: { $ langFilePath} ! " );
70
71
}
71
72
} catch (Exception $ e ) {
72
73
error_log ($ e ->getMessage ());
0 commit comments