├── .phpstorm.meta.php
├── LICENSE
├── README.md
├── composer.json
└── src
├── Debug
├── LanguageCollection.php
├── LanguageCollector.php
└── icons
│ └── language.svg
├── FallbackLevel.php
└── Language.php
/.phpstorm.meta.php:
--------------------------------------------------------------------------------
1 |
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 | namespace PHPSTORM_META;
11 |
12 | registerArgumentsSet(
13 | 'date_styles',
14 | 'full',
15 | 'long',
16 | 'medium',
17 | 'short',
18 | );
19 | registerArgumentsSet(
20 | 'currencies',
21 | 'AED',
22 | 'AFN',
23 | 'ALL',
24 | 'AMD',
25 | 'ANG',
26 | 'AOA',
27 | 'ARS',
28 | 'AUD',
29 | 'AWG',
30 | 'AZN',
31 | 'BAM',
32 | 'BBD',
33 | 'BDT',
34 | 'BGN',
35 | 'BHD',
36 | 'BIF',
37 | 'BMD',
38 | 'BND',
39 | 'BOB',
40 | 'BOV',
41 | 'BRL',
42 | 'BSD',
43 | 'BTN',
44 | 'BWP',
45 | 'BYN',
46 | 'BZD',
47 | 'CAD',
48 | 'CDF',
49 | 'CHE',
50 | 'CHF',
51 | 'CHW',
52 | 'CLF',
53 | 'CLP',
54 | 'CNY',
55 | 'COU',
56 | 'CRC',
57 | 'CUC',
58 | 'CUP',
59 | 'CVE',
60 | 'CZK',
61 | 'DJF',
62 | 'DKK',
63 | 'DOP',
64 | 'DZD',
65 | 'EGP',
66 | 'ERN',
67 | 'ETB',
68 | 'EUR',
69 | 'FJD',
70 | 'FKP',
71 | 'GBP',
72 | 'GEL',
73 | 'GHS',
74 | 'GIP',
75 | 'GMD',
76 | 'GNF',
77 | 'GTQ',
78 | 'GYD',
79 | 'HKD',
80 | 'HNL',
81 | 'HRK',
82 | 'HTG',
83 | 'HUF',
84 | 'IDR',
85 | 'ILS',
86 | 'INR',
87 | 'IQD',
88 | 'IRR',
89 | 'ISK',
90 | 'JMD',
91 | 'JOD',
92 | 'JPY',
93 | 'KES',
94 | 'KGS',
95 | 'KHR',
96 | 'KMF',
97 | 'KPW',
98 | 'KRW',
99 | 'KWD',
100 | 'KYD',
101 | 'KZT',
102 | 'LAK',
103 | 'LBP',
104 | 'LKR',
105 | 'LRD',
106 | 'LSL',
107 | 'LYD',
108 | 'MAD',
109 | 'MDL',
110 | 'MGA',
111 | 'MKD',
112 | 'MMK',
113 | 'MNT',
114 | 'MOP',
115 | 'MRU',
116 | 'MUR',
117 | 'MVR',
118 | 'MWK',
119 | 'MXN',
120 | 'MXV',
121 | 'MYR',
122 | 'MZN',
123 | 'NAD',
124 | 'NGN',
125 | 'NIO',
126 | 'NOK',
127 | 'NPR',
128 | 'NZD',
129 | 'OMR',
130 | 'PAB',
131 | 'PEN',
132 | 'PGK',
133 | 'PHP',
134 | 'PKR',
135 | 'PLN',
136 | 'PYG',
137 | 'QAR',
138 | 'RON',
139 | 'RSD',
140 | 'RUB',
141 | 'RWF',
142 | 'SAR',
143 | 'SBD',
144 | 'SCR',
145 | 'SDG',
146 | 'SEK',
147 | 'SGD',
148 | 'SHP',
149 | 'SLL',
150 | 'SOS',
151 | 'SRD',
152 | 'SSP',
153 | 'STN',
154 | 'SVC',
155 | 'SYP',
156 | 'SZL',
157 | 'THB',
158 | 'TJS',
159 | 'TMT',
160 | 'TND',
161 | 'TOP',
162 | 'TRY',
163 | 'TTD',
164 | 'TWD',
165 | 'TZS',
166 | 'UAH',
167 | 'UGX',
168 | 'USD',
169 | 'USN',
170 | 'UYI',
171 | 'UYU',
172 | 'UYW',
173 | 'UZS',
174 | 'VED',
175 | 'VES',
176 | 'VND',
177 | 'VUV',
178 | 'WST',
179 | 'XAF',
180 | 'XAG',
181 | 'XAU',
182 | 'XBA',
183 | 'XBB',
184 | 'XBC',
185 | 'XBD',
186 | 'XCD',
187 | 'XDR',
188 | 'XOF',
189 | 'XPD',
190 | 'XPF',
191 | 'XPT',
192 | 'XSU',
193 | 'XTS',
194 | 'XUA',
195 | 'XXX',
196 | 'YER',
197 | 'ZAR',
198 | 'ZMW',
199 | 'ZWL',
200 | );
201 | registerArgumentsSet(
202 | 'fallback_levels',
203 | \Framework\Language\Language::FALLBACK_DEFAULT,
204 | \Framework\Language\Language::FALLBACK_NONE,
205 | \Framework\Language\Language::FALLBACK_PARENT,
206 | );
207 | registerArgumentsSet(
208 | 'locales',
209 | 'aa',
210 | 'ab',
211 | 'af',
212 | 'ak',
213 | 'als',
214 | 'am',
215 | 'an',
216 | 'ang',
217 | 'ang',
218 | 'ar',
219 | 'arc',
220 | 'as',
221 | 'ast',
222 | 'av',
223 | 'awa',
224 | 'ay',
225 | 'az',
226 | 'ba',
227 | 'bar',
228 | 'bat-smg',
229 | 'bcl',
230 | 'be',
231 | 'be-x-old',
232 | 'bg',
233 | 'bh',
234 | 'bi',
235 | 'bm',
236 | 'bn',
237 | 'bo',
238 | 'bpy',
239 | 'br',
240 | 'brx',
241 | 'bs',
242 | 'bug',
243 | 'bxr',
244 | 'ca',
245 | 'cdo',
246 | 'ce',
247 | 'ceb',
248 | 'ch',
249 | 'cho',
250 | 'chr',
251 | 'chy',
252 | 'ckb',
253 | 'co',
254 | 'cr',
255 | 'cs',
256 | 'csb',
257 | 'cu',
258 | 'cv',
259 | 'cy',
260 | 'da',
261 | 'de',
262 | 'diq',
263 | 'dsb',
264 | 'dv',
265 | 'dz',
266 | 'ee',
267 | 'el',
268 | 'en',
269 | 'eo',
270 | 'es',
271 | 'et',
272 | 'eu',
273 | 'ext',
274 | 'fa',
275 | 'ff',
276 | 'fi',
277 | 'fiu-vro',
278 | 'fj',
279 | 'fo',
280 | 'fr',
281 | 'frp',
282 | 'fur',
283 | 'fy',
284 | 'ga',
285 | 'gan',
286 | 'gbm',
287 | 'gd',
288 | 'gil',
289 | 'gl',
290 | 'gn',
291 | 'got',
292 | 'gu',
293 | 'gv',
294 | 'ha',
295 | 'hak',
296 | 'haw',
297 | 'he',
298 | 'hi',
299 | 'ho',
300 | 'hr',
301 | 'ht',
302 | 'hu',
303 | 'hy',
304 | 'hz',
305 | 'ia',
306 | 'id',
307 | 'ie',
308 | 'ig',
309 | 'ii',
310 | 'ik',
311 | 'ilo',
312 | 'inh',
313 | 'io',
314 | 'is',
315 | 'it',
316 | 'iu',
317 | 'ja',
318 | 'jbo',
319 | 'jv',
320 | 'ka',
321 | 'kg',
322 | 'khw',
323 | 'ki',
324 | 'kj',
325 | 'kk',
326 | 'kl',
327 | 'km',
328 | 'kn',
329 | 'ko',
330 | 'kr',
331 | 'ks',
332 | 'ksh',
333 | 'ku',
334 | 'kv',
335 | 'kw',
336 | 'ky',
337 | 'la',
338 | 'lad',
339 | 'lan',
340 | 'lb',
341 | 'lg',
342 | 'li',
343 | 'lij',
344 | 'lmo',
345 | 'ln',
346 | 'lo',
347 | 'lt',
348 | 'lv',
349 | 'lzz',
350 | 'man',
351 | 'map-bms',
352 | 'mg',
353 | 'mh',
354 | 'mi',
355 | 'min',
356 | 'mk',
357 | 'ml',
358 | 'mn',
359 | 'mo',
360 | 'mr',
361 | 'mrh',
362 | 'ms',
363 | 'mt',
364 | 'mus',
365 | 'mwl',
366 | 'my',
367 | 'na',
368 | 'nah',
369 | 'nap',
370 | 'nd',
371 | 'nds',
372 | 'nds-nl',
373 | 'ne',
374 | 'new',
375 | 'ng',
376 | 'nl',
377 | 'nn',
378 | 'no',
379 | 'nr',
380 | 'nrm',
381 | 'nso',
382 | 'nv',
383 | 'ny',
384 | 'oc',
385 | 'oj',
386 | 'om',
387 | 'or',
388 | 'os',
389 | 'pa',
390 | 'pag',
391 | 'pam',
392 | 'pap',
393 | 'pdc',
394 | 'pi',
395 | 'pih',
396 | 'pl',
397 | 'pms',
398 | 'ps',
399 | 'pt',
400 | 'pt-br',
401 | 'qu',
402 | 'rm',
403 | 'rmy',
404 | 'rn',
405 | 'ro',
406 | 'roa-rup',
407 | 'ru',
408 | 'rw',
409 | 'sa',
410 | 'sc',
411 | 'scn',
412 | 'sco',
413 | 'sd',
414 | 'se',
415 | 'sg',
416 | 'sh',
417 | 'si',
418 | 'simple',
419 | 'sk',
420 | 'sl',
421 | 'sm',
422 | 'sn',
423 | 'so',
424 | 'sq',
425 | 'sr',
426 | 'ss',
427 | 'st',
428 | 'su',
429 | 'sv',
430 | 'sw',
431 | 'ta',
432 | 'te',
433 | 'tet',
434 | 'tg',
435 | 'th',
436 | 'ti',
437 | 'tk',
438 | 'tl',
439 | 'tlh',
440 | 'tn',
441 | 'to',
442 | 'tpi',
443 | 'tr',
444 | 'ts',
445 | 'tt',
446 | 'tum',
447 | 'tw',
448 | 'ty',
449 | 'udm',
450 | 'ug',
451 | 'uk',
452 | 'ur',
453 | 'uz',
454 | 'uz-af',
455 | 've',
456 | 'vec',
457 | 'vi',
458 | 'vls',
459 | 'vo',
460 | 'wa',
461 | 'war',
462 | 'wo',
463 | 'xal',
464 | 'xh',
465 | 'xmf',
466 | 'yi',
467 | 'yo',
468 | 'za',
469 | 'zh',
470 | 'zh-classical',
471 | 'zh-min-nan',
472 | 'zh-yue',
473 | 'zu',
474 | );
475 | registerArgumentsSet(
476 | 'locale_directions',
477 | 'ltr',
478 | 'rtl',
479 | );
480 | expectedArguments(
481 | \Framework\Language\Language::currency(),
482 | 1,
483 | argumentsSet('currencies')
484 | );
485 | expectedArguments(
486 | \Framework\Language\Language::date(),
487 | 1,
488 | argumentsSet('date_styles')
489 | );
490 | expectedArguments(
491 | \Framework\Language\Language::setFallbackLevel(),
492 | 0,
493 | argumentsSet('fallback_levels')
494 | );
495 | expectedArguments(
496 | \Framework\Language\Language::__construct(),
497 | 0,
498 | argumentsSet('locales')
499 | );
500 | expectedArguments(
501 | \Framework\Language\Language::addLines(),
502 | 0,
503 | argumentsSet('locales')
504 | );
505 | expectedArguments(
506 | \Framework\Language\Language::currency(),
507 | 2,
508 | argumentsSet('locales')
509 | );
510 | expectedArguments(
511 | \Framework\Language\Language::date(),
512 | 2,
513 | argumentsSet('locales')
514 | );
515 | expectedArguments(
516 | \Framework\Language\Language::formatMessage(),
517 | 2,
518 | argumentsSet('locales')
519 | );
520 | expectedArguments(
521 | \Framework\Language\Language::getLocaleDirection(),
522 | 0,
523 | argumentsSet('locales')
524 | );
525 | expectedArguments(
526 | \Framework\Language\Language::lang(),
527 | 2,
528 | argumentsSet('locales')
529 | );
530 | expectedArguments(
531 | \Framework\Language\Language::ordinal(),
532 | 1,
533 | argumentsSet('locales')
534 | );
535 | expectedArguments(
536 | \Framework\Language\Language::render(),
537 | 3,
538 | argumentsSet('locales')
539 | );
540 | expectedArguments(
541 | \Framework\Language\Language::setCurrentLocale(),
542 | 0,
543 | argumentsSet('locales')
544 | );
545 | expectedArguments(
546 | \Framework\Language\Language::setDefaultLocale(),
547 | 0,
548 | argumentsSet('locales')
549 | );
550 | expectedReturnValues(
551 | \Framework\Language\Language::getCurrentLocale(),
552 | argumentsSet('locales')
553 | );
554 | expectedReturnValues(
555 | \Framework\Language\Language::getCurrentLocaleDirection(),
556 | argumentsSet('locale_directions')
557 | );
558 | expectedReturnValues(
559 | \Framework\Language\Language::getDefaultLocale(),
560 | argumentsSet('locales')
561 | );
562 | expectedReturnValues(
563 | \Framework\Language\Language::getLocaleDirection(),
564 | argumentsSet('locale_directions')
565 | );
566 | expectedReturnValues(
567 | \Framework\Language\Language::getFallbackLevel(),
568 | argumentsSet('fallback_levels')
569 | );
570 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Natan Felles
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Aplus Framework Language Library
4 |
5 | - [Home](https://aplus-framework.com/packages/language)
6 | - [User Guide](https://docs.aplus-framework.com/guides/libraries/language/index.html)
7 | - [API Documentation](https://docs.aplus-framework.com/packages/language.html)
8 |
9 | [](https://github.com/aplus-framework/language/actions/workflows/tests.yml)
10 | [](https://coveralls.io/github/aplus-framework/language?branch=master)
11 | [](https://packagist.org/packages/aplus/language)
12 | [](https://aplus-framework.com/sponsor)
13 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aplus/language",
3 | "description": "Aplus Framework Language Library",
4 | "license": "MIT",
5 | "type": "library",
6 | "keywords": [
7 | "language",
8 | "lang",
9 | "locale",
10 | "localization",
11 | "internationalization",
12 | "i18n",
13 | "l10n",
14 | "intl"
15 | ],
16 | "authors": [
17 | {
18 | "name": "Natan Felles",
19 | "email": "natanfelles@gmail.com",
20 | "homepage": "https://natanfelles.github.io"
21 | }
22 | ],
23 | "homepage": "https://aplus-framework.com/packages/language",
24 | "support": {
25 | "email": "support@aplus-framework.com",
26 | "issues": "https://github.com/aplus-framework/language/issues",
27 | "forum": "https://aplus-framework.com/forum",
28 | "source": "https://github.com/aplus-framework/language",
29 | "docs": "https://docs.aplus-framework.com/guides/libraries/language/"
30 | },
31 | "funding": [
32 | {
33 | "type": "Aplus Sponsor",
34 | "url": "https://aplus-framework.com/sponsor"
35 | }
36 | ],
37 | "require": {
38 | "php": ">=8.3",
39 | "ext-intl": "*",
40 | "aplus/debug": "^4.3",
41 | "aplus/helpers": "^4.0"
42 | },
43 | "require-dev": {
44 | "ext-xdebug": "*",
45 | "aplus/coding-standard": "^2.8",
46 | "ergebnis/composer-normalize": "^2.25",
47 | "jetbrains/phpstorm-attributes": "^1.0",
48 | "phpmd/phpmd": "^2.13",
49 | "phpstan/phpstan": "^1.9",
50 | "phpunit/phpunit": "^10.5"
51 | },
52 | "minimum-stability": "dev",
53 | "prefer-stable": true,
54 | "autoload": {
55 | "psr-4": {
56 | "Framework\\Language\\": "src/"
57 | }
58 | },
59 | "autoload-dev": {
60 | "psr-4": {
61 | "Tests\\Language\\": "tests/"
62 | }
63 | },
64 | "config": {
65 | "allow-plugins": {
66 | "ergebnis/composer-normalize": true
67 | },
68 | "optimize-autoloader": true,
69 | "preferred-install": "dist",
70 | "sort-packages": true
71 | },
72 | "extra": {
73 | "branch-alias": {
74 | "dev-master": "4.x-dev"
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Debug/LanguageCollection.php:
--------------------------------------------------------------------------------
1 |
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 | namespace Framework\Language\Debug;
11 |
12 | use Framework\Debug\Collection;
13 |
14 | /**
15 | * Class LanguageCollection.
16 | *
17 | * @package language
18 | */
19 | class LanguageCollection extends Collection
20 | {
21 | protected string $iconPath = __DIR__ . '/icons/language.svg';
22 | }
23 |
--------------------------------------------------------------------------------
/src/Debug/LanguageCollector.php:
--------------------------------------------------------------------------------
1 |
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 | namespace Framework\Language\Debug;
11 |
12 | use Framework\Debug\Collector;
13 | use Framework\Debug\Debugger;
14 | use Framework\Language\Language;
15 |
16 | /**
17 | * Class LanguageCollector.
18 | *
19 | * @package language
20 | */
21 | class LanguageCollector extends Collector
22 | {
23 | protected Language $language;
24 |
25 | public function setLanguage(Language $language) : static
26 | {
27 | $this->language = $language;
28 | return $this;
29 | }
30 |
31 | public function getActivities() : array
32 | {
33 | $activities = [];
34 | foreach ($this->getData() as $index => $data) {
35 | $activities[] = [
36 | 'collector' => $this->getName(),
37 | 'class' => static::class,
38 | 'description' => 'Render message ' . ($index + 1),
39 | 'start' => $data['start'],
40 | 'end' => $data['end'],
41 | ];
42 | }
43 | return $activities;
44 | }
45 |
46 | public function getContents() : string
47 | {
48 | if (!isset($this->language)) {
49 | return '
A Language instance has not been set on this collector.
'; 50 | } 51 | \ob_start(); ?> 52 |Default Locale: = 53 | \htmlentities($this->language->getDefaultLocale()) 54 | ?>
55 |Current Locale: = 56 | \htmlentities($this->language->getCurrentLocale()) 57 | ?>
58 |Supported Locales: = 59 | \htmlentities(\implode(', ', $this->language->getSupportedLocales())) 60 | ?>
61 |Fallback Level: language->getFallbackLevel(); 63 | echo "{$level->value} ({$level->name})"; ?>
64 |No message has been rendered.
'; 78 | } 79 | $count = \count($this->getData()); 80 | \ob_start(); ?> 81 |= $count ?> message= $count === 1 ? '' : 's' ?> has been rendered.
82 |# | 86 |File | 87 |Line | 88 |Message | 89 |Locale | 90 |Time | 91 |
---|---|---|---|---|---|
= $index + 1 ?> | 97 |= \htmlentities($data['file']) ?> | 98 |= \htmlentities($data['line']) ?> | 99 |
100 |
101 | |
102 | = \htmlentities($data['locale']) ?> | 103 |= Debugger::roundSecondsToMilliseconds($data['end'] - $data['start']) ?> | 104 |
No directory set for this Language instance.
'; 117 | } 118 | $count = \count($directories); 119 | \ob_start(); ?> 120 |There = $count === 1 ? 'is 1 directory' : "are {$count} directories" ?> set.
121 |# | 125 |Directory | 126 |
---|---|
= $index + 1 ?> | 132 |= \htmlentities($directory) ?> | 133 |
No file lines available for this Language instance.
'; 146 | } 147 | $count = \count($lines); 148 | \ob_start(); ?> 149 |There = $count === 1 ? 'is 1 message line' : "are {$count} message lines" 150 | ?> available to the current locale (= $this->language->getCurrentLocale() ?>). 151 |
152 |# | 156 |File | 157 |Line | 158 |Message Pattern | 159 |Locale | 160 |Fallback | 161 |
---|---|---|---|---|---|
= $index + 1 ?> | 167 |= \htmlentities($line['file']) ?> | 168 |= \htmlentities($line['line']) ?> | 169 |
170 | 171 | |
172 | = \htmlentities($line['locale']) ?> | 173 |= \htmlentities($line['fallback']) ?> | 174 |