Skip to content

Commit a3efd3b

Browse files
authored
Merge pull request #29 from matriphe/feature-add-capitalize-name
Feature Add Capitalize Native Name
2 parents 6c1a2ce + 8d8c4ed commit a3efd3b

7 files changed

Lines changed: 611 additions & 99 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uses: shivammathur/setup-php@v2
3535
with:
3636
php-version: ${{ matrix.php-version }}
37-
extensions: mbstring
37+
extensions: mbstring xdebug
3838
tools: composer:v2
3939

4040
- name: Check PHP extensions
@@ -56,4 +56,4 @@ jobs:
5656
run: composer install --prefer-dist --no-progress
5757

5858
- name: Run test
59-
run: vendor/bin/phpunit
59+
run: composer run-script test:coverage

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ composer.lock
33
*.cache
44

55
# PhpStorm IDE
6-
/.idea
6+
/.idea
7+
8+
# Coverage reports
9+
/coverage
10+
coverage.xml
11+
.phpunit.cache

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ echo $iso->nativeByCode1('en'); // English
4747
echo $iso->nativeByCode1('id'); // Bahasa Indonesia
4848
echo $iso->nativeByCode1('jv'); // basa Jawa
4949

50+
// Get native language name from ISO-639-1 code with capitalized
51+
echo $iso->nativeByCode1('en', true); // English
52+
echo $iso->nativeByCode1('id', true); // Bahasa Indonesia
53+
echo $iso->nativeByCode1('jv', true); // Basa Jawa
54+
echo $iso->nativeByCode1('hi', true); // हिन्दी, हिंदी
55+
echo $iso->nativeByCode1('th', true); // ไทย
56+
echo $iso->nativeByCode1('ko', true); // 한국어
57+
echo $iso->nativeByCode1('ja', true); // 日本語 (にほんご)
58+
echo $iso->nativeByCode1('zh', true); // '中文 (Zhōngwén), 汉语, 漢語
59+
echo $iso->nativeByCode1('ru', true); // Русский
60+
echo $iso->nativeByCode1('ar', true); // االعربية
61+
echo $iso->nativeByCode1('vi', true); // Việt Nam
62+
5063
// Get language name from ISO-639-2t code
5164
echo $iso->languageByCode2t('eng'); // English
5265
echo $iso->languageByCode2t('ind'); // Indonesian
@@ -57,6 +70,19 @@ echo $iso->nativeByCode2t('eng'); // English
5770
echo $iso->nativeByCode2t('ind'); // Bahasa Indonesia
5871
echo $iso->nativeByCode2t('jav'); // basa Jawa
5972

73+
// Get native language name from ISO-639-2t code with capitalized
74+
echo $iso->nativeByCode2t('eng', true); // English
75+
echo $iso->nativeByCode2t('ind', true); // Bahasa Indonesia
76+
echo $iso->nativeByCode2t('jav', true); // Basa Jawa
77+
echo $iso->nativeByCode2t('hin', true); // हिन्दी, हिंदी
78+
echo $iso->nativeByCode2t('tha', true); // ไทย
79+
echo $iso->nativeByCode2t('kor', true); // 한국어
80+
echo $iso->nativeByCode2t('jpn', true); // 日本語 (にほんご)
81+
echo $iso->nativeByCode2t('zho', true); // '中文 (Zhōngwén), 汉语, 漢語
82+
echo $iso->nativeByCode2t('rus', true); // Русский
83+
echo $iso->nativeByCode2t('ara', true); // االعربية
84+
echo $iso->nativeByCode2t('vie', true); // Việt Nam
85+
6086
// Get language name from ISO-639-2b code
6187
echo $iso->languageByCode2b('eng'); // English
6288
echo $iso->languageByCode2b('ind'); // Indonesian
@@ -67,6 +93,19 @@ echo $iso->nativeByCode2b('eng'); // English
6793
echo $iso->nativeByCode2b('ind'); // Bahasa Indonesia
6894
echo $iso->nativeByCode2b('jav'); // basa Jawa
6995

96+
// Get native language name from ISO-639-2b code with capitalized
97+
echo $iso->nativeByCode2b('eng', true); // English
98+
echo $iso->nativeByCode2b('ind', true); // Bahasa Indonesia
99+
echo $iso->nativeByCode2b('jav', true); // Basa Jawa
100+
echo $iso->nativeByCode2b('hin', true); // हिन्दी, हिंदी
101+
echo $iso->nativeByCode2b('tha', true); // ไทย
102+
echo $iso->nativeByCode2b('kor', true); // 한국어
103+
echo $iso->nativeByCode2b('jpn', true); // 日本語 (にほんご)
104+
echo $iso->nativeByCode2b('chi', true); // '中文 (Zhōngwén), 汉语, 漢語
105+
echo $iso->nativeByCode2b('rus', true); // Русский
106+
echo $iso->nativeByCode2b('ara', true); // االعربية
107+
echo $iso->nativeByCode2b('vie', true); // Việt Nam
108+
70109
// Get language name from ISO-639-3 code
71110
echo $iso->languageByCode3('eng'); // English
72111
echo $iso->languageByCode3('ind'); // Indonesian
@@ -77,6 +116,19 @@ echo $iso->nativeByCode3('eng'); // English
77116
echo $iso->nativeByCode3('ind'); // Bahasa Indonesia
78117
echo $iso->nativeByCode3('jav'); // basa Jawa
79118

119+
// Get native language name from ISO-639-3 code with capitalized
120+
echo $iso->nativeByCode3('eng', true); // English
121+
echo $iso->nativeByCode3('ind', true); // Bahasa Indonesia
122+
echo $iso->nativeByCode3('jav', true); // Basa Jawa
123+
echo $iso->nativeByCode3('hin', true); // हिन्दी, हिंदी
124+
echo $iso->nativeByCode3('tha', true); // ไทย
125+
echo $iso->nativeByCode3('kor', true); // 한국어
126+
echo $iso->nativeByCode3('jpn', true); // 日本語 (にほんご)
127+
echo $iso->nativeByCode3('zho', true); // '中文 (Zhōngwén), 汉语, 漢語
128+
echo $iso->nativeByCode3('rus', true); // Русский
129+
echo $iso->nativeByCode3('ara', true); // االعربية
130+
echo $iso->nativeByCode3('vie', true); // Việt Nam
131+
80132
// Get language array from ISO-639-2b code
81133
echo $iso->getLanguageByIsoCode2b('eng'); // ['en', 'eng', 'eng', 'eng', 'English', 'English']
82134
echo $iso->getLanguageByIsoCode2b('ind'); // ['id', 'ind', 'ind', 'ind', 'Indonesian', 'Bahasa Indonesia']

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"php": "8.*"
1919
},
2020
"suggest": {
21-
"ext-mbstring": "For better multibyte character support in text transformations"
21+
"ext-mbstring": "For better multibyte character support in text transformations",
22+
"ext-xdebug": "For code coverage when running tests"
2223
},
2324
"autoload": {
2425
"psr-4": {
@@ -29,6 +30,10 @@
2930
"lint": "php-cs-fixer fix --dry-run --diff",
3031
"lint:fix": "php-cs-fixer fix",
3132
"test": "phpunit",
33+
"test:coverage": "XDEBUG_MODE=coverage phpunit --coverage-text",
34+
"test:coverage-html": "XDEBUG_MODE=coverage phpunit --coverage-html coverage",
35+
"test:coverage-xml": "XDEBUG_MODE=coverage phpunit --coverage-clover coverage.xml",
36+
"test:no-coverage": "phpunit --no-coverage",
3237
"check": [
3338
"@lint",
3439
"@test"

phpunit.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php">
2+
<phpunit bootstrap="vendor/autoload.php"
3+
colors="true"
4+
cacheDirectory=".phpunit.cache">
35
<testsuites>
46
<testsuite name="ISO-639 Test Unit">
5-
<directory suffix=".php">tests</directory>
7+
<directory>tests</directory>
68
</testsuite>
79
</testsuites>
10+
<source>
11+
<include>
12+
<directory suffix=".php">src</directory>
13+
</include>
14+
</source>
815
</phpunit>

src/ISO639.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,11 @@ public function languageByCode1(string $code): string
312312
/*
313313
* Get native language name from ISO-639-1 (two-letters code)
314314
*/
315-
public function nativeByCode1(string $code): string
315+
public function nativeByCode1(string $code, bool $isCapitalized = false): string
316316
{
317-
return $this->iso639_1[$this->toLower($code)][self::KEY_NATIVE] ?? '';
317+
$native = $this->iso639_1[$this->toLower($code)][self::KEY_NATIVE] ?? '';
318+
319+
return $isCapitalized ? $this->toTitleCase($native) : $native;
318320
}
319321

320322
/*
@@ -328,9 +330,11 @@ public function languageByCode2t(string $code): string
328330
/*
329331
* Get native language name from ISO-639-2/t (three-letter codes) terminologic
330332
*/
331-
public function nativeByCode2t(string $code): string
333+
public function nativeByCode2t(string $code, bool $isCapitalized = false): string
332334
{
333-
return $this->iso639_2t[$this->toLower($code)][self::KEY_NATIVE] ?? '';
335+
$native = $this->iso639_2t[$this->toLower($code)][self::KEY_NATIVE] ?? '';
336+
337+
return $isCapitalized ? $this->toTitleCase($native) : $native;
334338
}
335339

336340
/*
@@ -344,9 +348,11 @@ public function languageByCode2b(string $code): string
344348
/*
345349
* Get native language name from ISO-639-2/b (three-letter codes) bibliographic
346350
*/
347-
public function nativeByCode2b($code): string
351+
public function nativeByCode2b(string $code, bool $isCapitalized = false): string
348352
{
349-
return $this->iso639_2b[$this->toLower($code)][self::KEY_NATIVE] ?? '';
353+
$native = $this->iso639_2b[$this->toLower($code)][self::KEY_NATIVE] ?? '';
354+
355+
return $isCapitalized ? $this->toTitleCase($native) : $native;
350356
}
351357

352358
/*
@@ -360,9 +366,11 @@ public function languageByCode3($code): string
360366
/*
361367
* Get native language name from ISO-639-3 (three-letter codes)
362368
*/
363-
public function nativeByCode3(string $code): string
369+
public function nativeByCode3(string $code, bool $isCapitalized = false): string
364370
{
365-
return $this->iso639_3[$this->toLower($code)][self::KEY_NATIVE] ?? '';
371+
$native = $this->iso639_3[$this->toLower($code)][self::KEY_NATIVE] ?? '';
372+
373+
return $isCapitalized ? $this->toTitleCase($native) : $native;
366374
}
367375

368376
/*

0 commit comments

Comments
 (0)