DV-JF Posted August 12, 2021 Share Posted August 12, 2021 (edited) Hey all, I'm setting up a site with 3 languages: default = German en = English zh = Chinese simplified Is it possible to set all Chinese fields which are not translated yet to English instead of the default language German? In the settings of the fields I can only choose the default one? I was trying to edit / mess around the file wire/modules/LanguageSupport/LanguagesPageFieldValue.php but without any luck. Is there maybe any hook I could use to accomplish my purpose? Many greets, Jens alias DV-JF Edited August 16, 2021 by DV-JF Solved - Thanks to Zeka! Link to comment Share on other sites More sharing options...
Zeka Posted August 12, 2021 Share Posted August 12, 2021 Hi. Not tested but should work $this->wire()->addHookAfter('LanguagesPageFieldValue::getStringValue', function ($event) { $value = $event->return; $languagesPageFieldValue = $event->object; $languages = $this->wire()->languages; $userLanguageID = $this->wire()->user->language->id; $chineseLanguageID = $languages->get('chinese')->id; $newFallbackLanguageID = $languages->get('english')->id; if($userLanguageID === $chineseLanguageID && !$languagesPageFieldValue->getLanguageValue($chineseLanguageID)) { $value = $languagesPageFieldValue->getLanguageValue($newFallbackLanguageID); if(!strlen($value)) { $value = $languagesPageFieldValue->getDefaultValue(); } }; $event->return = $value; }); 3 4 Link to comment Share on other sites More sharing options...
DV-JF Posted August 16, 2021 Author Share Posted August 16, 2021 @Zeka Thank you, this is exactly what I was searching for! Link to comment Share on other sites More sharing options...
MSP01 Posted May 3, 2022 Share Posted May 3, 2022 Now a questions, is it possible to hook language strings in the same manner? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now