PHP code example of smartness / translation-client
1. Go to this page and download the library: Download smartness/translation-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smartness / translation-client example snippets
// lang/en/auth.php
return [
'failed' => 'These credentials do not match our records.',
'password' => 'The provided password is incorrect.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
// Nested arrays for dot-notation keys
'verification' => [
'sent' => 'A fresh verification link has been sent to your email address.',
'verified' => 'Your email address has been verified.',
],
];
namespace App\Services;
use Smartness\TranslationClient\TranslationClient;
class TranslationSync
{
public function __construct(
protected TranslationClient $client
) {}
// Pull translations
public function syncTranslations(string $language): array
{
// Fetch translations as Laravel PHP arrays
$response = $this->client->fetchAsPhp($language);
return $response['data'];
}
public function syncAsJson(string $language): array
{
// Fetch translations as JSON format
$response = $this->client->fetchAsJson($language);
return $response['data'];
}
public function getRawTranslations(string $language): array
{
// Fetch raw format with metadata
$response = $this->client->fetchRaw($language);
return $response['data'];
}
// Push translations
public function pushTranslations(array $translations, bool $overwrite = false): array
{
// Push all translations
return $this->client->push($translations, [
'overwrite' => $overwrite,
]);
}
public function pushLanguageTranslations(string $language, array $translations, bool $overwrite = false): array
{
// Push translations for a specific language
return $this->client->pushLanguage($language, $translations, $overwrite);
}
public function pushFileTranslations(string $language, string $filename, array $translations): array
{
// Push a specific translation file
return $this->client->pushFile($language, $filename, $translations);
}
public function verifyConnection(): bool
{
return $this->client->testConnection();
}
}
return [
// API endpoint (TION_API_URL'),
// API authentication token (ranslation files
// Default: lang_path() resolves to 'lang/' directory
'output_dir' => env('TRANSLATION_OUTPUT_DIR', null),
// Format: json, php, or raw
'format' => env('TRANSLATION_FORMAT', 'php'),
// Status filter: approved, pending, rejected, or null (all)
'status_filter' => env('TRANSLATION_STATUS', 'approved'),
// HTTP request timeout in seconds
'timeout' => env('TRANSLATION_TIMEOUT', 30),
];