0
0
mirror of https://github.com/sp-tarkov/db-website.git synced 2025-02-08 02:10:54 -05:00

Made changes to accomidate the new locales layout, works on my local setup

This commit is contained in:
SPT-dev 2023-03-02 20:51:51 -05:00
parent 81090eb0f3
commit a13271717f

View File

@ -33,32 +33,53 @@ class ItemsCollection
} }
} }
/**
* Refeshes the locales for the items and clothing
*
* @return void
*/
public function refreshLocalesCache(): void public function refreshLocalesCache(): void
{ {
$this->locales = collect(); $this->locales = collect();
$rawLocalesGlobalBaseUrl = GiteaConfig::RAW_LOCALES_GLOBAL_BASE_URL; $rawLocalesGlobalBaseUrl = GiteaConfig::RAW_LOCALES_GLOBAL_BASE_URL;
// Getting all locales in project/assets/database/locales/global from the Server development branch repository
$localesList = collect(Http::withOptions(['verify' => false])->get(GiteaConfig::LOCALES_GLOBAL_URL)->json()); $localesList = collect(Http::withOptions(['verify' => false])->get(GiteaConfig::LOCALES_GLOBAL_URL)->json());
foreach ($localesList as $item) {
// Extract the json name for the locale
preg_match('/([a-z]{2}(-[a-z]{2})?).json/', $item['name'], $currentLocaleName, PREG_OFFSET_CAPTURE);
// If the name is not supported for any reason, dont add it to the locales foreach ($localesList as $locale)
{
// Extract the json name for the locale
preg_match('/([a-z]{2}(-[a-z]{2})?).json/', $locale['name'], $currentLocaleName, PREG_OFFSET_CAPTURE);
if (empty($currentLocaleName) || !$currentLocaleName[1][0]) continue; if (empty($currentLocaleName) || !$currentLocaleName[1][0]) continue;
$trimmedCurrentLocaleName = trim($currentLocaleName[1][0]); $trimmedCurrentLocaleName = trim($currentLocaleName[1][0]);
$currentLocaleJson = Http::withOptions(['verify' => false])
->get("${rawLocalesGlobalBaseUrl}/${trimmedCurrentLocaleName}.json")->json(); $currentLocaleJson = Http::withOptions(['verify' => false])->get($rawLocalesGlobalBaseUrl . $trimmedCurrentLocaleName . ".json")->json();
$templateLocale = collect($currentLocaleJson['templates']);
$customizationLocale = collect($currentLocaleJson['customization']); $templates = [];
$this->locales = $this->locales->merge([$trimmedCurrentLocaleName => $templateLocale->concat($customizationLocale)]);
} foreach ($this->items as $item) {
if ($item['_type'] === 'Node' || !property_exists((object) $currentLocaleJson, $item['_id'].' Name')) continue;
$array = [
"Name" => $currentLocaleJson[$item['_id'].' Name'],
"ShortName" => $currentLocaleJson[$item['_id'].' ShortName'],
"Description" => $currentLocaleJson[$item['_id'].' Description']
];
//var_dump($item);die;
$templates[$item['_id']] = $array;
}
$this->locales = $this->locales->merge(collect([$trimmedCurrentLocaleName => $templates]));
}
Cache::put($this->locales_cache_key, $this->locales); Cache::put($this->locales_cache_key, $this->locales);
} }
/** /**
* Refreshes the items of the DB
*
* @return void * @return void
*/ */
public function refreshItemsCache(): void public function refreshItemsCache(): void
@ -83,7 +104,7 @@ class ItemsCollection
public function refreshAllCache(): void public function refreshAllCache(): void
{ {
$this->refreshItemsCache(); $this->refreshItemsCache();
$this->refreshLocalesCache(); //$this->refreshLocalesCache();
} }
/** /**