-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Loader
Michael Spiss edited this page Aug 17, 2017
·
4 revisions
Loaders are used to parse data from any file format into an array.
Creating a custom loader is a painless, three step process:
- Create a new class which implements
MichaelSpiss\Translation\LoaderInterface
<?php
use MichaelSpiss\Translation\LoaderInterface;
class CustomLoader implements LoaderInterface {
public function getContent( string $file ): array { }
}
-
Implement the getContent() method. For further information about this method see the method definition below.
-
After that you only have to make sure that your loader is known to the
Translator
by calling its addLoader method after initialization:
$translator = new Translator('en', 'path/to/translations');
$translator->addLoader('yml', new YamlLoader());
public function getContent( string $file ): array
Gets translation data from a file and turns it into an array.
Arguments:
-
string $file
: The file which needs to be parsed
Returns:
The parsed array. Should be of the following format:
[
'key' => 'translation string',
'another' = [
'subkey' => 'another string'
]
]