Language Packages
The seven endpoints that see, copy, set up and remove the installed languages.
Overview
A language lives in three places at once in WISECP: the package file (name, country, order, state), the translation files and the language tables holding product names, category titles and notification templates. This article manages the first and the whole.
A new language is never born empty; it is set up by copying one that is installed. The copy takes both the table rows and the file tree, which makes it heavy work.
One language is the default and that one is privileged: it cannot be closed, cannot be removed, and carries no language prefix in its addresses. Moving the default swaps those three behaviours between two languages.
Reference
Listing the Installed Languages
Returns every language on the installation, the closed ones included.
curl 'https://panel.example.com/api/v1/admin/languages' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/languages', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data, meta } = await res.json();
const live = data.filter((l) => l.status);$ch = curl_init('https://panel.example.com/api/v1/admin/languages');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// The closed ones come too; filter on status for the languages open to a client.
$r = Api::Languages()->GetLanguages();
$live = array_values(array_filter($r['data'], fn ($l) => $l['status']));
$def = $r['meta']['default'];Listing What Can Be Downloaded
Returns the languages the WISECP translation service offers.
curl 'https://panel.example.com/api/v1/admin/languages/available' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/languages/available', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data, meta } = await res.json();
if (meta.count === 0) showRetry();$ch = curl_init('https://panel.example.com/api/v1/admin/languages/available');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// AN EMPTY LIST means one of two things: none exist or the remote service failed. They look alike.
$out = Api::Languages()->GetAvailableLanguages();
if (! $out['data']) $logger->warning('empty language list — check the service is reachable');Reading One Language
Returns one language package.
curl 'https://panel.example.com/api/v1/admin/languages/de' \
-H "Authorization: Bearer $API_KEY"const res = await fetch(`https://panel.example.com/api/v1/admin/languages/${key}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/languages/' . $key);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// The key is not the language CODE: a second country under one code takes the 'en-gb' form.
$pkg = Api::Languages()->GetLanguage(['key' => $key])['data'];Making a Language by Copying
Sets up a new language by copying one that is installed.
curl -X POST 'https://panel.example.com/api/v1/admin/languages' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"copy_language":"en","language":"de","country_id":276,"show_name":"Deutsch"}'const res = await fetch('https://panel.example.com/api/v1/admin/languages', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
copy_language: 'en',
language: 'de',
country_id: 276,
show_name: 'Deutsch',
rank: 2,
}),
});
const { data } = await res.json();
const realKey = data.key; // 'de' olmayabilir$ch = curl_init('https://panel.example.com/api/v1/admin/languages');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'copy_language' => 'en',
'language' => 'de',
'country_id' => 276,
'show_name' => 'Deutsch',
]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// When the code you send IS already installed the key becomes 'code-country'; read it, do not assume.
$pkg = Api::Languages()->CreateLanguage([
'copy_language' => 'en', 'language' => 'en',
'country_id' => 826, 'show_name' => 'English (UK)',
])['data'];
$key = $pkg['key']; // 'en-gb'Changing a Language's Settings
Changes the fields you send and can promote the language to default.
curl -X PATCH 'https://panel.example.com/api/v1/admin/languages/de' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"show_name":"Deutsch","rank":2}'const res = await fetch(`https://panel.example.com/api/v1/admin/languages/${key}`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ show_name: 'Deutsch', rank: 2 }),
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/languages/' . $key);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['show_name' => 'Deutsch', 'rank' => 2]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// On the DEFAULT language status is IGNORED: the answer is 200 while the language stays on.
$pkg = Api::Languages()->UpdateLanguage(['key' => $key, 'status' => 0])['data'];
if ($pkg['status']) $logger->info('the default language cannot be closed — nothing changed');Turning a Language On and Off
Opens a language to clients or closes it.
curl -X PUT 'https://panel.example.com/api/v1/admin/languages/de/status' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"status":1}'const res = await fetch(`https://panel.example.com/api/v1/admin/languages/${key}/status`, {
method: 'PUT',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ status: 1 }),
});
if (res.status === 422) { /* zaten aciksa buraya duser */ }$ch = curl_init('https://panel.example.com/api/v1/admin/languages/' . $key . '/status');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['status' => 1]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// Writing the same state again is an ERROR; read the current one first during a bulk sync.
$pkg = Api::Languages()->GetLanguage(['key' => $key])['data'];
if ($pkg['status'] !== $wanted) Api::Languages()->SetLanguageStatus(['key' => $key, 'status' => (int) $wanted]);Removing a Language
Removes a language, its translations and every row belonging to it.
curl -X DELETE 'https://panel.example.com/api/v1/admin/languages/de' \
-H "Authorization: Bearer $API_KEY"const res = await fetch(`https://panel.example.com/api/v1/admin/languages/${key}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/languages/' . $key);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// The product and category names IN THAT LANGUAGE go as well; export and keep them first.
$dump = Api::Languages()->ExportLanguageTranslations(['key' => $key])['data'];
file_put_contents("backup-$key.json", json_encode($dump));
Api::Languages()->DeleteLanguage(['key' => $key]);Pitfalls
When the language code you send is already installed, the new key takes the code-country form. Setting up a second English makes en-gb rather than en. Read the key from the answer, since every later call wants it.
Making a language the default opens the prefix on the old default and closes it on the new one. The public addresses of both languages change and the old links shift. The job also rewrites the settings file and forces the new language open. Do not run it unplanned on a live installation.
The status endpoint turns down closing the default language with 422. The settings endpoint ignores the same request quietly and answers 200 while the language stays open. A script mixing the two believes it closed something. Look at the state in the answer.
The status endpoint answers 422 with no_change when the state you ask for is the one already there. The endpoint is not repeatable: a sync loop setting every language to open errors on the ones that are open. Read the current state before writing.
Removing a language takes the translation files, the notification templates and the language table rows: the product names, category titles and page content in that language go with it. The only way back is a backup. Export the translations first.
The downloadable languages come from a remote service. When it cannot be reached the endpoint raises no error and returns an empty list. That makes "no languages" and "the service failed" look alike. Leave a way to retry before showing an empty result as "nothing to pick".
Related Articles
Merci pour votre retour !
Notre équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas ci-dessus.