Jump to content

funny little multilingual page create issue


virtualgadjo
 Share

Recommended Posts

Hi all,

i'm running into a funny  little issue
i'm working on a multilingual website, default is English, second language French

in this website i've a form for visitors to submit an event, title, date and so on, when they submit the event, it's stored into a personnal db table
i've created a module in the admin where admins (well, of course ? ) can't validate or delete the submitted events, thanks to pw, it works like breeze except for one little thing ?

when an admin validate an event, i use the pw api to create a page and fill all the new page fields, among which
 

$p = new Page();
$p->of(false);
....
$p->title = $titre;

$titre being the title of the event submitted and retreived from the database

the thing is that depending of the language of the admin it fills the title in English/the default language or in French if the admin language is French and what i'm looking for is to always fill the default language title whatever the admin language is, guess, to take advantage of the auto filling of other languages when the default one is filled

Funny enough i've solved the opposite problem with a multilingual select form field, using
 

$filters = $fieldtypes->get('FieldtypeOptions')->getOptions('filtres');
foreach($filters as $f):
...
echo $f->title; // it always echo the default language option title
// using this
echo $liso == 'fr' ? $f->title1019 : $f->title; // i've got the right select options titles displayed in the select
// of course, $liso is defined in the _init.php
$langid  = $user->language->id;
$langiso = array(1017 => 'en', 1019 => 'fr');
$liso    = $langiso[$langid];

in case anybody has an idea about this page creation ?
i keep searching

have a nice day
chris

Link to comment
Share on other sites

The easiest way to make sure you always populate the default language, is a one-liner before all your regular page-creation functions:

$languages->setLanguage("default");

and of course, if you always explicitly want to edit the french value:
$languages->setLanguage("fr");

  • Like 1
Link to comment
Share on other sites

Hi Dragan,

and thanks a lot for your answer
the thing is it's exactly what i was trying to do but
---
Undefined variable: languages in D:\wamp\www\moodforweb\champagne_day\site\modules\ValidEvents\ValidEvents.module on line 157
Uncaught Error: Call to a member function setLanguage() on null in D:\wamp\www\moodforweb\champagne_day\site\modules\ValidEvents\ValidEvents.module on line 157
---
i'm spinning around this set Language thing, deep inside the api i'll probably find something, a way to define $languages when in a module or something like that

actually, i just want to avoid populating the french value, too bad as it's exactly what it does when the admin language is french ?
i'll try something with data as the title table has data for english/default and date 1019 for the french one

thanks again and have a nice day

Link to comment
Share on other sites

hi again,

just one more funny thing, using
$bool = $languages->setLanguage("default");
as shown by Ryan in the api, works fine on the front end but throws an error in a module, probably because it's conflicting with the admin language
(answer to myself ? no, it's just because le $languages var is defined for the front end not for an admin custom page)

still have to dig a little more

i'll tell you if i find out (hope so ? )

Link to comment
Share on other sites

I guess inside a module you have to use wire('languages')->setLanguage("foo") instead of $languages (not sure, no time to counter-check). 

1 hour ago, virtualgadjo said:

$p->title->setLanguageValue('default', $titre);

Nice one... didn't know that method existed like that. Well, that's certainly even better. The wonders of the PW API never ceases to amaze me ?

Link to comment
Share on other sites

59 minutes ago, dragan said:

Nice one... didn't know that method existed like that. Well, that's certainly even better. The wonders of the PW API never ceases to amaze me ?

me neither and me too ?
with all the funny things PW allows me to do, i was sure there was something clever somewhere deep in the API, a few tests later, it worked!

my clients love PW but probably less than i do... everytime i'm wondering "can i do this"... yes i can (i sound like an american election baseline ? )

have a nice day
chris

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

×
×
  • Create New...