joe_g Posted Thursday at 05:33 PM Share Posted Thursday at 05:33 PM Hey hello, So i've got a site with no less than 13 languages. Not everything exists in all languages. The way "active" works is that if it's unchecked, then that particular language-version of a page gives a 404. What I'd like it to do instead is to still show the page, but with the content from the default language instead of throwing a 404. Ideally no page should ever give a 404. However, I suppose that's not so easy to accomplish? The plan B would be for me to implement my own "active" switch. But I don't think there is such a thing as a multilingual checkbox (that can be checked individually per language). Or is there? Maybe there is a third way I don't see right now? Link to comment Share on other sites More sharing options...
gebeer Posted Friday at 08:45 AM Share Posted Friday at 08:45 AM If you leave active checked, it will automatically fall back to the default language. This behavior is the default behavior. You can change that behavior per language field in the Details tab Link to comment Share on other sites More sharing options...
joe_g Posted 4 hours ago Author Share Posted 4 hours ago Yes thank you. I don't think I explained myself very well. So I have a website with 13 potential languages, not all of them are used everywhere. Most pages have 2-3 languages out of these 13. I would like to show a language switch for the languages that has been translated (in most cases 2-3 languages). The problem is that there is no easy way for me to know what languages has actually been translated. I can't go through all the fields and compare them to the default language because it's tons of repeaters with text fields with footnotes and whatnot. It would easily be over 20-30 textfields to compare so this would be inefficient. So, I would need some kind of mechanism or switch that the editor can use to say "this language is in use". I can't use the "active" switch because if i switch it off the page gives a 404. Ideally, active=off would mean "return the page with the default language", but that's not how it works. I would like to add my own checkbox called "use this language", but I don't think there is anything like a "Multilingual Checkbox"? What i do now is that i compare the title with default, if it's different then I assume the page is translated. This does't work very well since the title sometimes stays the same. The client is not so happy with this solution. The only way to achieve this that I can think of is to have a text field called "is this page translated" that the editor would fill in with anything (such as "yes"). But that feels soo hacky and weird. Is there a better way? Link to comment Share on other sites More sharing options...
virtualgadjo Posted 4 hours ago Share Posted 4 hours ago Hi, as i assume the 404 issue is only for the front side of your web site, i think the problem is only when on a page you change the language.... what you can easyly solve when building your lang switcher foreach($languages as $language) { if( ! $page->viewable($language) ) continue; // here is the trick $url = $page->localUrl($language); $iso = $language->name == 'default' ? 'fr' : $language->name; // fr here but of course chang it for your default language iso $local_title = $language->getLanguageValue($language->name, 'title'); // here comes your output with flags/iso code or whatever you want :) } with this a page that doesn't exist in a language will not have the language button in the switcher and shouldn't appear in the menu for this language when you are on another page i've made a video and have a github repo with language menu tricks and exmples but, too bad, in french as there are very few reesources for the french guys using or discovering pw 🙂 sorry if i've understood your question in a wrong way have a nice day 1 Link to comment Share on other sites More sharing options...
gebeer Posted 2 hours ago Share Posted 2 hours ago In one of my projects I have a separate field 'langs' that editors can check. Definition (for RockMigrations): 'langs' => [ 'label' => 'Languages', 'tags' => 'general', 'flags' => 0, 'type' => 'FieldtypePage', 'derefAsPage' => 0, 'inputfield' => 'InputfieldCheckboxes', 'parent_id' => '', 'labelFieldName' => 'title', 'optionColumns' => 1, 'template_id' => 'language', ], So it is a page reference field that gives you checkboxes for each language. You could then use the value of this field in your logic for the language switch. Link to comment Share on other sites More sharing options...
joe_g Posted 1 hour ago Author Share Posted 1 hour ago Thank you both. @virtualgadjo I would love to stick to the native "active" if i can, however it's a bit cumbersome to check if a page is "viewable" *everywhere* when its being linked to. It could be in the language switch, but it is linked in lots of places. I Example: /es/hola-amigo (spanish page) /about (default about) /nl/about (dutch about) /es/about (NOT ACTIVE, DOESN'T EXIST) If i link from /es/hola-amigo to /es/about (without checking if it's viewable) i get a 404. What I like it to do is to instead go to /about .........Aaaaaaaaaaaaaaaaaaand after looking around a bit, there it is. This is what I didn't know existed because I didn't look hard enough 🤦♂️🤦♂️🤦♂️🤦♂️ thanks for the help! J Link to comment Share on other sites More sharing options...
virtualgadjo Posted 1 hour ago Share Posted 1 hour ago Hi @joe_g what i think could be more interesting to you is in the settings tab of a page, when you unckeck active for a language, then in the language swsitch the page is not viewable for this language, hence the "trick" in my little snippet and, this way, you haven't got to change pw default behaviour 🙂 hope it may help have a nice day Link to comment Share on other sites More sharing options...
joe_g Posted 1 hour ago Author Share Posted 1 hour ago The problem is not the language switch, it's everywhere else the page is linked. It wouldn't be enough to check if it's 'viewable' in the language switch - it would have to happen everywhere. That would be hard. But the 302 redirect setting makes this a non-problem Link to comment Share on other sites More sharing options...
joe_g Posted 1 hour ago Author Share Posted 1 hour ago @gebeer Is what you describe some native setting or is it part of your module? Link to comment Share on other sites More sharing options...
virtualgadjo Posted 1 hour ago Share Posted 1 hour ago @joe_g actually, the page souldn't be linked from anywhere on the website as, using pw native link module, language by language it should not appear in the page select, this active thing is useful for the menus as well as the language sitch, too bad my video is in French i explain and demonstrate all this (being french most the websites i make use at least two languages when not, like yours, more and i've had to dig a lot in this languages things 🙂) have a nice day Link to comment Share on other sites More sharing options...
joe_g Posted 1 hour ago Author Share Posted 1 hour ago yes, you made me understand 'viewable', that's great. But i can't control internal links done in ckedit (for example). Maybe ckedit is linked to /es/page and that doesn't yet exist (but perhaps a week later someone makes a spanish translation). It should work both now and later. Link to comment Share on other sites More sharing options...
virtualgadjo Posted 54 minutes ago Share Posted 54 minutes ago hi again 🙂 actually if by ckedit you mean ckeditor, as the content of each field tab is linked to a language, the pages for which the edited language is not active should not appear in the pages select when you add a link to an internal page the pw way and, when you do in another language, landing on this page, the language switch will not propose the language it's not available in as very often pw makes things so simple i too keep running into that kind of situation many times when i wonder, how to do this or that... and wow, it's native! 🙂 have a nice day 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