famousinteractive / content-api
Allow to get translations via an Api and specific helper
Installs: 372
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/famousinteractive/content-api
Requires
- php: >=5.6
- guzzlehttp/guzzle: ~6.0
README
Set up a package to load translation from centralized api
Basic Installation
-
composer require famousinteractive/content-api -
Add
Famousinteractive\ContentApi\ContentApiServiceProvider::classin serviceProvider in config/app.php -
Publish the config file :
php artisan vendor:publish -
Create the project on the translation platform
-
Launch the command
php artisan famousContentApi:initializeto generate the config file
Usage
- use
fitrans($key, $params = [], $lang = null, $default = '')to use the translation via the Content Api.
Dataset
-
To get the data of a dataset, use the function
fitds($datasetName, $prefixLang = false, $param=[], $useCache=true)$datasetNameis the unique name of the dataset$prefixLangBoolean allowing you to use a different dataset for each language.$paramstring with the data to return. Values :- "fields" Just the list and the type of the fields.
- "datas" All entries in the dataset with information on the fields.
- "formatted" An array with the association with Field => value and no more data.
- "All" All these data in once. By default
$useCacheBoolean. True by default. If you get data who change often (like dataset to store user data for example), you may prefer to not cache the result.
-
To put new record in a dataset, use the function
fitpushds($datasetName, $data=[], $prefixLang = false)$datasetNameand$prefixLanghave the same behavior as for fitds() function$datais an array with an association of field name and value.[ 'lastname' => 'Dillenbourg', 'firstname' => 'Jérémy', 'birtdate' => '1990-07-03' ]
- The return is either true or an array
['success' => false, 'message' => 'error_description']. The fields are validated by the rules set in the platform. If the validation fails, you'll receive an error response.
Extra
- You can call
/fit-content-api-clear-cache?clientId=xxxxxxin order to clear the cache of the website - You can run
php artisan famousContentApi:collectto collect all the fitrans() reference and send them to the platform. - You can force to render all the translation key by adding paremeters to the url of your website
?fitrans=display_keys&exclusion=routes- fitrans=display_keys render all the keys, fitrans=edit_keys generate html tags handled by the chrome extension
- exlusion exlude some pattern. Here all keys starting by
routes.. It's usefull if you use fitrans() in the route file.