Skip to content

Commit

Permalink
options translation
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterjan.eilers committed Sep 2, 2024
1 parent 0c388ff commit 7f770e4
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 31 deletions.
51 changes: 42 additions & 9 deletions modules/registrars/realtimeregister/lang/english.additional.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
// phpcs:ignoreFile
/**
* WHMCS Language File for RTR module additional domain fields
* English (en)
Expand All @@ -13,12 +12,46 @@
* http://docs.whmcs.com/Language_Overrides
*/

$_LANG['tld_nu_orgno_label'] = 'Unique data set or Organization number';
$_LANG['tld_nu_orgno_description'] = 'Corporate identity number or personal identification number for swedish contacts (for non Swedish, any other unique identification number can be used instead)';
$_LANG['tld_nu_vatno_label'] = 'Vat number';
$_LANG['tld_nu_vatno_description'] = 'VAT registration number (only for foreign legal entities within the EU who are registered to pay VAT)';
$_LANG['tld_es_identificationnumber_label'] = 'Unique data set, organization number or NIE or NIF';
$_LANG['tld_es_identificationnumber_description'] = 'Unique data set, organization number or NIE or NIF';
$_LANG['tld_es_entitytype_label'] = 'Entity type';
$_LANG['tld_es_entitytype_description'] = 'Legal entity form of your business';
$_LANG['tld_es_entitytype_1'] = '1. Individual';
$_LANG['tld_es_entitytype_68'] = '68. Professional Association';
$_LANG['tld_es_entitytype_197'] = '197. Public Law Association';
$_LANG['tld_es_entitytype_713'] = '713. Spanish Office';
$_LANG['tld_es_entitytype_203'] = '203. Embassy';
$_LANG['tld_es_entitytype_524'] = '524. Public Limited Company';
$_LANG['tld_es_entitytype_269'] = '269. Sports Federation';
$_LANG['tld_es_entitytype_525'] = '525. Sports Association';
$_LANG['tld_es_entitytype_717'] = '717. Temporary Alliance of Enterprises';
$_LANG['tld_es_entitytype_150'] = '150. Community Property';
$_LANG['tld_es_entitytype_152'] = '152. Community of Owners';
$_LANG['tld_es_entitytype_476'] = '476. Trade Union';
$_LANG['tld_es_entitytype_286'] = '286. Foundation';
$_LANG['tld_es_entitytype_608'] = '608. Worker-owned Company';
$_LANG['tld_es_entitytype_164'] = '164. Order or Religious Institution';
$_LANG['tld_es_entitytype_612'] = '612. Limited Company';
$_LANG['tld_es_entitytype_229'] = '229. Local Authority';
$_LANG['tld_es_entitytype_39'] = '39. Economic Interest Group';
$_LANG['tld_es_entitytype_744'] = '744. Worker-owned Limited Company';
$_LANG['tld_es_entitytype_745'] = '745. Regional Public Entity';
$_LANG['tld_es_entitytype_554'] = '554. Civil Society';
$_LANG['tld_es_entitytype_746'] = '746. National Public Entity';
$_LANG['tld_es_entitytype_747'] = '747. Local Public Entity';
$_LANG['tld_es_entitytype_365'] = '365. Mutual Insurance Company';
$_LANG['tld_es_entitytype_877'] = '877. Others';
$_LANG['tld_es_entitytype_878'] = '878. Designation of Origin Supervisory Council';
$_LANG['tld_es_entitytype_47'] = '47. Association';
$_LANG['tld_es_entitytype_879'] = '879. Entity Managing Natural Areas';
$_LANG['tld_es_entitytype_560'] = '560. General Partnership';
$_LANG['tld_es_entitytype_434'] = '434. Regional Government Body';
$_LANG['tld_es_entitytype_562'] = '562. General and Limited Partnership';
$_LANG['tld_es_entitytype_436'] = '436. Central Government Body';
$_LANG['tld_es_entitytype_181'] = '181. Consulate';
$_LANG['tld_es_entitytype_566'] = '566. Cooperative';
$_LANG['tld_es_entitytype_439'] = '439. Political Party';
$_LANG['tld_es_entitytype_59'] = '59. Sports Association';
$_LANG['tld_es_entitytype_124'] = '124. Savings Bank';
$_LANG['tld_es_entitytype_510'] = '510. Farm Partnership';

$_LANG['tld_se_orgno_label'] = 'Unique data set or Organization number';
$_LANG['tld_se_orgno_description'] = 'Corporate identity number or personal identification number for swedish contacts (for non Swedish, any other unique identification number can be used instead)';
$_LANG['tld_se_vatno_label'] = 'Vat number';
$_LANG['tld_se_vatno_description'] = 'VAT registration number (only for foreign legal entities within the EU who are registered to pay VAT)';
10 changes: 8 additions & 2 deletions modules/registrars/realtimeregister/realtimeregister.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use RealtimeRegister\Actions\Domains\Sync;
use RealtimeRegister\App;
use RealtimeRegister\ConfigArray;
use WHMCS\Domains\DomainLookup\ResultsList;
use WHMCS\Domains\DomainLookup\SearchResult;

if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
Expand All @@ -31,9 +33,13 @@ function realtimeregister_getConfigArray(): array
return (new ConfigArray())();
}

function realtimeregister_CheckAvailability(array $params)
function realtimeregister_CheckAvailability(array $params): ResultsList
{
return App::dispatch(CheckAvailability::class, $params);
return App::dispatch(
CheckAvailability::class,
$params,
['RealtimeRegister\Actions\Domains\CheckAvailability', 'handleException']
);
}

function realtimeregister_GetDomainInformation(array $params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,24 @@ public function __invoke(Request $request)
}
return $results;
}

public static function handleException(\Throwable $exception, array $params) : ResultsList {
$resultList = new ResultsList();

$query = $_REQUEST['domain'];
$searchTerm = $params['searchTerm'];

if ($query !== $searchTerm) {
$searchResult = new SearchResult($searchTerm, "." . MetadataService::getTld($query));
} else {
$searchResult = new SearchResult($searchTerm, array_keys(App::localApi()->getTldPricing())[0]);
}

$searchResult->setStatus(SearchResult::STATUS_UNKNOWN);
$resultList->append($searchResult);

logActivity("Error while checking domain" . $query . ": " . $exception->getMessage());

return $resultList;
}
}
3 changes: 2 additions & 1 deletion modules/registrars/realtimeregister/src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SandwaveIo\RealtimeRegister\IsProxy;
use SandwaveIo\RealtimeRegister\RealtimeRegister;


class App
{
public const NAME = 'realtimeregister';
Expand Down Expand Up @@ -145,7 +146,7 @@ public static function dispatch(string $action, array $params = [], callable $ca
return static::instance()->dispatchTo($action, $params);
} catch (\Throwable $exception) {
if ($catch) {
return $catch($exception);
return $catch($exception, $params);
}

if ($exception instanceof ActionFailedException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

ini_set('max_execution_time', 0);


$tlds = MetadataService::getAllTlds();
$re = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
$regex = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
$entry = "\$_LANG['%s'] = '%s';\n";
$lines = [];

Expand All @@ -25,17 +24,24 @@
$label = $property['label'];
if (strlen($label) > 70) {
$name = str_replace(['-', '_'], ' ', $property['name']);
$label = ucfirst(strtolower(preg_replace($re, ' \0', $name)));
$label = ucfirst(strtolower(preg_replace($regex, ' \0', $name)));
}
$label = addcslashes($label, "'");
$description = addcslashes($property['description'], "'");
$langvar = MetadataService::toLangVar($tld, $property['name']);
$lines[] = sprintf($entry, $langvar . '_label', $label);
$lines[] = sprintf($entry, $langvar . '_description', $description);

if ($property['values']) {
foreach ($property['values'] as $key => $value) {
$lines[] = sprintf($entry, $langvar . '_' . $key, $value);
}
}
}
$lines[] = "\n";
}
} catch (\Exception $ignored) {
} catch (\Exception $e) {
logActivity("Exception in update_additional_fields while getting metadata for " . $tld . ": " . $e->getMessage());
continue;
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/registrars/realtimeregister/src/LocalApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ public function getTldPricing()
if ($result) {
return $result['pricing'];
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getTldAdditionalFields(): array
if ($properties) {
foreach ($properties as $property) {
$default = array_key_exists($property['name'], $current) ? $current[$property['name']] : null;
$tldAdditionalFields[] = self::propertyToAdditionalField($this->tld, $property, $default);
$tldAdditionalFields[] = $this->propertyToAdditionalField($property, $default);
}
}
return ['fields' => $tldAdditionalFields, 'applicableFor' => $this->info->applicableFor];
Expand Down Expand Up @@ -154,10 +154,10 @@ public static function toLangVar(string $tld, string $property_name): string
return sprintf('tld_%s_%s', strtolower($tld), preg_replace('/[^a-z0-9]/', '', strtolower($property_name)));
}

private static function propertyToAdditionalField($tld, $property, $default = null): array
private function propertyToAdditionalField($property, $default = null): array
{
global $_LANG;
$langvar = self::toLangVar($tld, $property['name']);
$langvar = self::toLangVar($this->tld, $property['name']);
$field = [
'Name' => $property['name'],
'LangVar' => $langvar . '_label',
Expand All @@ -173,7 +173,7 @@ private static function propertyToAdditionalField($tld, $property, $default = nu
$field['Type'] = 'tickbox';
} else {
$field['Type'] = 'dropdown';
$field['Options'] = self::arrayToOptions($property['values'], $property['name']);
$field['Options'] = $this->arrayToOptions($property['values'], $property['name']);
}
} else {
$field['Type'] = 'text';
Expand Down Expand Up @@ -202,26 +202,20 @@ public static function getPropertyBoolValue($propertyValues, $bool)
return array_intersect($bool ? ['true', 'y'] : ['false', 'n'], array_keys($propertyValues))[0];
}

private static function arrayToOptions(array $propertyValues, string $propertyName): string
private function arrayToOptions(array $propertyValues, string $propertyName): string
{
global $_LANG;

$options = [];
foreach ($propertyValues as $key => $value) {
$translation = sprintf('tld_properties_%s', preg_replace('/[^a-z0-9_]/', '', strtolower($key)));

$translationKey = sprintf(
'tld_properties_%s_%s',
'tld_%s_%s_%s',
strtolower($this->tld),
preg_replace('/[^a-z0-9_]/', '', strtolower($propertyName)),
preg_replace('/[^a-z0-9_]/', '', strtolower($key))
);

if (!empty($_LANG[$translationKey])) {
$value = $_LANG[$translationKey];
} elseif (!empty($_LANG[$translation])) { // Fallback for when people used old translation keys
$value = $_LANG[$translation];
}
$options[] = self::strip($key) . '|' . self::strip($value);

$options[] = self::strip($key) . '|' . self::strip($_LANG[$translationKey]);
}
return ',' . implode(',', $options);
}
Expand Down

0 comments on commit 7f770e4

Please sign in to comment.