Skip to content

Commit ce7ed89

Browse files
committed
created v2.0
1 parent 4440068 commit ce7ed89

File tree

12 files changed

+414
-613
lines changed

12 files changed

+414
-613
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.0.2] - 2021-05-28
8+
## [1.0.3] - 2021-11-30
9+
### Changed
10+
- Dropped PHP5 support
911

12+
## [1.0.2] - 2021-05-28
1013
### Fixed
1114
- only start session if not already started
1215

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ new TranslatorAPI($settings);
6565
```
6666

6767
#### Requirements
68-
* PHP 5.6 and above
68+
* PHP 7.4 and above (tested with php8)
6969

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "pleinx/php-multilang-any",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"type": "library",
5-
"description": "Handles easy your translations for your multi language PHP Project.",
5+
"description": "A simple resolver for language snippets.",
66
"keywords": [
77
"php",
88
"i18n",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.php

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,52 @@
11
<?php
2-
/**
3-
* Notice: You dont need forcing a TranslatorSettings or the Static Translate (aka. TranslateMe) Class.
4-
* You can also use the Default Path (Check your Config)
5-
* Its just a Example how to use the Translator.
6-
*/
2+
/**
3+
* Notice: You dont need forcing a TranslatorSettings or the Static Translate (aka. TranslateMe) Class.
4+
* You can also use the Default Path (Check your Config)
5+
* Its just a Example how to use the Translator.
6+
*/
77

8-
// ========================= Initialize the Translator =========================
9-
use MultilangAny\Settings AS TranslatorSettings;
10-
use MultilangAny\TranslatorAPI;
8+
// ========================= Initialize the Translator =========================
9+
use MultilangAny\Settings as TranslatorSettings;
10+
use MultilangAny\TranslatorAPI;
1111

12-
// Give a custom alias, what you want
13-
// e.g. T = T::__(foo, bar)
14-
use MultilangAny\Translate AS TranslateMe;
12+
// Give a custom alias, what you want
13+
// e.g. T = T::__(foo, bar)
14+
use MultilangAny\Translate as TranslateMe;
1515

16-
require '../vendor/autoload.php';
16+
require '../vendor/autoload.php';
1717

18-
$translatorSettings = (new TranslatorSettings())
19-
->setIsProduction(false)
20-
->setLanguageFilesPath(__DIR__ . '/lang');
18+
$translatorSettings = (new TranslatorSettings())->setIsProduction(false)->setLanguageFilesPath(__DIR__ . '/lang');
2119

22-
$translator = new TranslatorAPI($translatorSettings);
20+
$translator = new TranslatorAPI($translatorSettings);
2321

24-
// ========================= Usage via Dependendcy Injection =========================
25-
echo $translator->translate('pkg_general.SayHelloTo', 'Tim');
26-
// Output in German: "Hallo Tim!" and in english: "Hello Tim"
22+
// ========================= Usage via Dependendcy Injection =========================
23+
echo $translator->translate('pkg_general.SayHelloTo', 'Tim');
24+
// Output in German: "Hallo Tim!" and in english: "Hello Tim"
2725

28-
// ========================= Usage via Static Class =========================
29-
TranslateMe::__e('pkg_general.SayHelloTo', 'Peter');
30-
// Output in German: "Hallo Peter!" and in english: "Hello Peter"
26+
// ========================= Usage via Static Class =========================
27+
TranslateMe::__e('pkg_general.SayHelloTo', 'Peter');
28+
// Output in German: "Hallo Peter!" and in english: "Hello Peter"
3129

32-
// ========================= Usage via known helper function =========================
33-
function __ ($messageKey, $arguments = []) {
34-
return TranslateMe::__($messageKey, $arguments);
35-
}
30+
// ========================= Usage via known helper function =========================
31+
function __ ($messageKey, $arguments = []) {
32+
return TranslateMe::__($messageKey, $arguments);
33+
}
3634

37-
function __e ($messageKey, $arguments = []) {
38-
TranslateMe::__e($messageKey, $arguments);
39-
}
35+
function __e ($messageKey, $arguments = []) {
36+
TranslateMe::__e($messageKey, $arguments);
37+
}
4038

41-
// As returned value
42-
$storeMessageSayHelloMessage = __('pkg_general.SayHelloTo', 'Sandra');
39+
// As returned value
40+
$storeMessageSayHelloMessage = __('pkg_general.SayHelloTo', 'Sandra');
4341

42+
// Direct echo
43+
__e('pkg_general.SayHelloTo', 'Sandra');
44+
// Output in German: "Hallo Sandra!" and in english: "Hello Sandra"
4445

45-
// Direct echo
46-
__e('pkg_general.SayHelloTo', 'Sandra');
47-
// Output in German: "Hallo Sandra!" and in english: "Hello Sandra"
46+
// ========================= Usage with multiply arguments =========================
47+
TranslateMe::__e('pkg_search.SearchedFor', ['RC Car', 'Toys']);
48+
// Output in English: Your search results for: "RC Car" in the category "Toys"
4849

49-
// ========================= Usage with multiply arguments =========================
50-
TranslateMe::__e('pkg_search.SearchedFor', ['RC Car', 'Toys']);
51-
// Output in English: Your search results for: "RC Car" in the category "Toys"
52-
53-
// or if you using one argument multiply in the message
54-
TranslateMe::__e('pkg_search.SearchResult', ['itemCount' => 5, 'itemCountTotal' => 10]);
55-
// Output in English: Found 5 from 10. Displayed items 5.
50+
// or if you using one argument multiply in the message
51+
TranslateMe::__e('pkg_search.SearchResult', ['itemCount' => 5, 'itemCountTotal' => 10]);
52+
// Output in English: Found 5 from 10. Displayed items 5.

src/Container.php

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
<?php
22

3-
namespace MultilangAny;
4-
5-
6-
/**
7-
* Class Container
8-
*
9-
* @package MultilangAny
10-
* @author Fabian Hesse <[email protected]>
11-
* Visit me on : https://github.com/pleinx
12-
*/
13-
class Container {
14-
15-
// On Production Modus you will only get critical errors
16-
const IS_PRODUCTION_MODUS = true;
17-
18-
// Default Fallback Language if a Message not in your current choosen Language avaialable
19-
const FALLBACK_LANGUAGE = 'en';
20-
21-
// Directory where the Translator find the Language-Resources
22-
const LANGUAGE_FILES_DIRECTORY = __DIR__ . '/LanguageFiles/';
23-
24-
// Default Pattern for searching Variables in a Message
25-
const MESSAGE_ARGUMENTS_PATTERN = '~\{\{\s*(.*?)\s*\}\}~'; // Hello {{name}}
26-
27-
// Default GET-Paramter if you set the Language via HTTP-Paramter
28-
const HTTP_LANGUAGE_PARAMTER = 'lang'; // e.g. ?lang=en
29-
30-
// Default SESSION-Parameter if you set the Language via Session
31-
const SESSION_LANGUAGE_PARAMTER = 'lang'; // e.g. $_SESSION['lang']
32-
33-
// Supported Language-File Extension
34-
const LANGUAGE_FILE_EXTENSION = 'json';
35-
}
3+
namespace MultilangAny;
4+
5+
/**
6+
* Class Container
7+
*
8+
* @package MultilangAny
9+
* @author Fabian Hesse <[email protected]>
10+
* Visit me on: https://github.com/pleinx
11+
*/
12+
class Container {
13+
14+
// On Production Modus you will only get critical errors
15+
const IS_PRODUCTION_MODUS = true;
16+
// Default Fallback Language if a Message not in your current choosen Language avaialable
17+
const FALLBACK_LANGUAGE = 'en';
18+
// Directory where the Translator find the Language-Resources
19+
const LANGUAGE_FILES_DIRECTORY = __DIR__ . '/LanguageFiles/';
20+
// Default Pattern for searching Variables in a Message
21+
const MESSAGE_ARGUMENTS_PATTERN = '~\{\{\s*(.*?)\s*\}\}~'; // Hello {{name}}
22+
// Default GET-Paramter if you set the Language via HTTP-Paramter
23+
const HTTP_LANGUAGE_PARAMTER = 'lang'; // e.g. ?lang=en
24+
// Default SESSION-Parameter if you set the Language via Session
25+
const SESSION_LANGUAGE_PARAMTER = 'lang'; // e.g. $_SESSION['lang']
26+
// Supported Language-File Extension
27+
const LANGUAGE_FILE_EXTENSION = 'json';
28+
}
Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
<?php
22

3-
namespace MultilangAny\Interfaces;
4-
5-
6-
/**
7-
* Interface MessageResolverInterface
8-
*
9-
* @package MultilangAny\Interfaces
10-
* @author Fabian Hesse <[email protected]>
11-
* Visit me on : https://github.com/pleinx
12-
*/
13-
interface MessageResolverInterface {
14-
15-
/**
16-
* @param $key
17-
* @param array $args
18-
*
19-
* @return string
20-
*/
21-
function resolve ($key, $args = []);
22-
}
3+
namespace MultilangAny\Interfaces;
4+
5+
/**
6+
* Interface MessageResolverInterface
7+
*
8+
* @package MultilangAny\Interfaces
9+
* @author Fabian Hesse <[email protected]>
10+
* Visit me on: https://github.com/pleinx
11+
*/
12+
interface MessageResolverInterface {
13+
14+
function resolve (string $key, $args = []);
15+
}

0 commit comments

Comments
 (0)