Jump to content

Don't substitute default language


Wanze
 Share

Recommended Posts

Having different languages and a multilang field's value is empty, the value of the default language is returned.

http://processwire.com/api/multi-language-support/multi-language-fields/#multi-language-field-values

Can we  change this behaviour? Is there any method to prevent this already at Db-Level? For example: I don't want to return pages that have an empty title in language xy.

This doesn't work:

<?php
//Default Language set
$pages->find("title!=''"); //Works!!

//Any other language
$pages->find("title!=''"); 
//Doesn't work, throws exception: Exception: Table 'db.field_title1' doesn't exist

I know I can set of = false and then get the unformatted language value, but would be cool to exclude those pages in a search query.

  • Like 1
Link to comment
Share on other sites

The exception that you got there would be a bug. I must have broken something during some recent updates to make it pass Nik's test suite. I'll investigate further. But I don't think this is related to your question. You should be able to target the value for a specific language like this (assuming I didn't break that too) :)

$pages->find("title.data$user->language=something"); 
  • Like 1
Link to comment
Share on other sites

Thanks ryan,

I didn't think of a bug.

Your example works fine for other languages than the default.

Made it work like this:

$langId = '';
if ($user->language->name != 'default') $langId = $user->language->id;
$pages->find("title.data{$langId)!='');

Query pages based on empty fields in other languages without this condition would be ultra-sexy :)

Link to comment
Share on other sites

Thanks ryan, I will test soon and report back.

@Soma

Yeah I'm using this solution on two sites at the moment.

But I think the trick with the title is in some situations easier to handle: No checkboxes, I don't forget to add them to a new template. Or if you have the checkboxes global and not every template needs them, that could be confusing too.

For the client it's an easy rule: If you don't set a title in language xy, this page won't get displayed. I think its a condition for the title to have a value, otherwise a page is not fully translated and therefore shouldn't output anything.

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   0 members

    • No registered users viewing this page.
×
×
  • Create New...