Jump to content

Uncheck Active without 404? Or other way to deal with languages?


joe_g
 Share

Recommended Posts

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

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

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

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   1 member

×
×
  • Create New...