Jump to content

Selective Multilingual Pages in ProcessWire


Recommended Posts

 

Hi everyone,

I run an English website, and I’m adding translations with ProcessWire. Right now, enabling a new language creates URLs for every page (and leads to 404 errors if the translation URL isn’t "Active").

Here’s what I’d like instead:

  • Translate in stages: Start with just a few pages (e.g. Page 1, Page 2, Page 3).
  • Language-specific nav: On translated pages, show links only to other active translations.
  • Fallback to English: If a visitor requests an untranslated page (like /de/contact or /de/blog), display the default URL (like /contact, /blog).

My site has dozens of pages, so a full translation will take months. I’d rather roll out a small batch each day to test and refine the process.

Does anyone know if ProcessWire can be configured this way? Any tips or examples would be much appreciated!

Thanks!

Link to comment
Share on other sites

@kuba go to the Languages Support - Page Names module and scroll down to the section Behavior when page not available in requested language (but is available in default language)

  • Like 2
Link to comment
Share on other sites

6 minutes ago, ngrmm said:

@kuba go to the Languages Support - Page Names module and scroll down to the section Behavior when page not available in requested language (but is available in default language)

Thank you for the hint, I guess this option "Perform a 302 (temporary) redirect to the page in default language" may work.

Link to comment
Share on other sites

Is there a gentler way to disable one language across all pages; the "Active" URL?

foreach ($page as $p) {
    $p->of(false);
    $p->setAndSave('status2818', false);
}
Link to comment
Share on other sites

13 hours ago, ngrmm said:

 

Thank you again for the reply. I did find this thread, but the solution doesn't work, at least with PW 3.0.246.

foreach ($languages->findNonDefault() as $language) {
    $page->setLanguageStatus($language, true);
}

$language returns the right ID, e.g. 2818.

setLanguageStatus does not affect anything, regardless of whether it is set to true or false.

The issue with setAndSave is that it cannot handle applying changes to all pages, hanging the whole platform. 

The RockMigrations module uses also setAndSave.

public function activate(HookEvent $event)
  {
    $page = $event->arguments(0);
    $languages = $this->wire->languages->findNonDefault();
    foreach ($languages as $lang) $page->setAndSave("status$lang", 1);
  }
Link to comment
Share on other sites

If you're having trouble managing the "Active URL" status through the CMS interface, I found that a direct database update may be the solution.

Here’s a working SQL command to
 
set status2818 = 0 for all selected language/pages(both published and unpublished):

UPDATE pages
SET status2818 = 0
WHERE published IS NULL 
   OR published IS NOT NULL;
  • Like 1
Link to comment
Share on other sites

Here is an API solution to disable page language, shared by Rayan, for anyone interested.
 
$wire->addHookBefore('InputfieldPageName::render', function(HookEvent $e) {
  $inputfield = $e->object;
  foreach($e->wire()->languages as $language) {
    $name = "status$language";
    if($inputfield->checkboxName != $name) continue;
    if($inputfield->checkboxChecked) {
      // Checkbox for $language->name is checked
    } else {
      // Checkbox for $language->name is not checked
    }
    // to change set $inputfield->checkboxChecked = true or false
  }
}, [ 'priority' => 200 ]);
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...