Jump to content

change default language revisited


gebeer

Recommended Posts

  • 1 year later...

After some tedious experiments, I finally managed to switch my site's default language from English to German both in frontend and backend. I am reliefed but not satisfied because it was a terrible hack:

  • Starting with @mscore's SQL script, I added a condition to make sure that field texts are only swapped if a translation exists
    SET s1.data = s1.data123, s1.data123 = s2.data WHERE s1.pages_id = s2.pages_id AND s1.data1019 != '';
    Especially important for backend field without translation, otherwise the backend text will get broken.
  • Then, I added some lines in order to update the option names for FieldtypeOptions:
    UPDATE fieldtype_options s1, fieldtype_options s2
    SET s1.title = s1.title123, s1.title123 = s2.title, s1.value = s1.value123, s1.value123 = s2.value
    WHERE s1.fields_id = s2.fields_id and s1.option_id = s2.option_id;
  • The following statements are necessary for keeping the correct translation files for both languages (let 124 be the page id of the default language):
    update field_language_files set pages_id = 123 where pages_id = 124;
    update field_language_files_site set pages_id = 123 where pages_id = 124;
  • Unfortunately, since translation files are stored in the assets, it is also necessary to swap the corresponding asset directory names: files/123 to files/124.
  • The final step is changing the title of the new non-default language ("deutsch" to "english") and the language names respective.

I can't understand why there's still no out-of-the-box solution for this use-case, which is IMHO not so unusual. I also would prefer a PW API solution like @gebeer's one, but I couldnt' find out how to iterate over really all stuff I need (including backend) ...

  • Like 3
Link to comment
Share on other sites

Just noticed that I'm still not finished ? The field labels and descriptions are still in the wrong language. This cannot be fixed by simple SQL since these values are JSON-encoded in the data column of the fields table ?

Maybe I'll try to write a PHP script with a mixture of PW API and raw SQL calls because I'm not familiar enough with PW internals for a cleaner solution. Maybe I already could be finished with the PW port of my site, but this default language issue wastes lots of lots of time ... on the other hand, it seems to be a blocker for me forcing my users to fill in all (English) default language fields if the site's text is by 95% in German.

Link to comment
Share on other sites

8 hours ago, FlorianA said:

it seems to be a blocker for me forcing my users to fill in all (English) default language fields if the site's text is by 95% in German.

If I understand this correctly, then your default language should be German. What was the reasoning behind switching languages in your case?

If you want to write a PHP script, maybe my old script can give you some pointers. I wrote that years ago when I wasn't very experienced in working with the PW API. So there sure is much room for improvement.

Link to comment
Share on other sites

@FlorianA maybe there is / was a misunderstanding? (I haven't read the thread, only the last posts)

You are able to do:

  • sites only in german,
  • sites with german as default language, and (multiple) other language(s) added

in ProcessWire with a snip, -- IF you start a new site right with the desired default language. Then your users only have to fill in the german fields, (and only optional other language(s)). 

Link to comment
Share on other sites

On 5/6/2020 at 11:28 AM, horst said:

@FlorianA maybe there is / was a misunderstanding? (I haven't read the thread, only the last posts)

You are able to do:

  • sites only in german,
  • sites with german as default language, and (multiple) other language(s) added

in ProcessWire with a snip, -- IF you start a new site right with the desired default language. Then your users only have to fill in the german fields, (and only optional other language(s)). 

@horst, that sounds really promising, unfortunatley I don't have a clue how to do this. I've just installed a new site from the ZIP file (master 3.0.148) with the "Multilanguage" site profile, but I couldn't see a possibility to prevent the default language from being English. I couldn't find any documentation about it either. I'll greatly appreciate any hints how to do the snip ?

  • Like 1
Link to comment
Share on other sites

Summary: When you start a new site and the default not should be english:

1) enable languages support 

2) set Title / Label of the default language to your desired none english native language, (e.g. 'Deutsch' (German))

3) drop in the none english language pack (for admin backend) into the default language, (e.g. german langpack)

Now you are ready to start with a single language site of your choice.

If you want to use a multi language site, you now can add as many additional languages you want. If one of them should be english, you add it, but do not need to apply a language pack.

4) add a new language to it and drop in a language pack for any none english language or simply don't drop in a language pack to get the english version (but not as the default one!)

For single language sites you only need to enable languages support, NOT language inputfields!, NOT language pagenames!, only basic language support, - to be able to change the default languages name and its lang pack!
Of course, if you plan a multilanguage site, you also will need language pagenames and language inputfields, but not if you only need a none english backend. ?

 

So, if you know at the beginning of a new site / project what has to be the default language, it is done with a snip. Only disadvantage is, if you need to switch the default language later on, when already content was filled into a site. These seems to be very rare cases in real life. And for that I think have read a complete step by step guide from @BitPoet within the last two or three month somewhere. (Is this right @BitPoet ? and sorry for ping you here) 

 

You also can read it here:

Edited by horst
  • Like 7
Link to comment
Share on other sites

1 hour ago, horst said:

Summary: When you start a new site and the default not should be english:

@horst,

Thanks for the write-up!

If you possibly can, for newbies, could you please make a diagram/flow chart for the instructions? Or at least add more details please?

For instance:

1 hour ago, horst said:

2) set Title / Label of the default language to your desired none english native language, (e.g. 'Deutsch' (German))

Where should this be done? ?

1 hour ago, horst said:

1) enable languages support 

Where should this be done? What does the user need to enable and/or download? ?

Etc.

Thanks for considering.

  • Like 2
Link to comment
Share on other sites

Quote

However, I noticed that it is a bad practice to modify the default language (english) with language files.
Instead you should add russian as an ADDITIONAL language and then set the guest user to this language (for the frontend) and also your admin user, so the PW admin is also in russian.

Maybe @dotnetic can elaborate why this is a bad practice?

  • Like 4
Link to comment
Share on other sites

Ok, I have read that linked post. But one question is: What kind of default URLs do we get in a multilanguage site when following @dotnetic's suggestion. (@Jens: ?)

I have created a series of screenshots, a full walk-through, of my suggested way, but I don't want to publish it, if it wouldn't be correct or if there be a better way. So here are my questions:

 

When I only want to have a single language page in none english, what is to do then?

How will the page pathes urls work out then with a second language set?

 

When I want to have a multi language site with none english default, but with english as second lang, what is to do?

How will the pages URLs work out for the none english default and the english sub language? 

 

 

EDIT: @bernhard, you was a bit faster, but I have more in depth questions. ?

 

Edited by horst
  • Like 2
  • Haha 1
Link to comment
Share on other sites

Change Default Language to be None-English | Walk Trough

When you start a new (single) language site and the default language shouldn't be English, you can change it this way:

Go to the modules core section:

pw_change-default-language__002.thumb.jpg.bc0be0ddf0ca31082da556d88407fc54.jpg

 

Select the Language ones by the filter function:

pw_change-default-language__003.thumb.jpg.dadd7e12d2e246d0195c29220194ae47.jpg

 

We have four language related modules here, but for a single language site in none english,
we only need the base module, named "Languages Support". So go on and install it.

pw_change-default-language__004.thumb.jpg.e9fa294589eb9aab1c9d849e8fc484ef.jpg

 

After that, you can leave it, ... 

pw_change-default-language__005.thumb.jpg.da49118b6996334225125ea121a6bdba.jpg

 

... and switch to the newly created Language section under SETUP:

pw_change-default-language__006.thumb.jpg.b52c53018304d58a5524cf9814b3ce03.jpg

 

Select the default language

pw_change-default-language__008.thumb.jpg.c6ab28344d0f532feeb2b582ee093c63.jpg

 

Enter your new language name or its Shortcut and save the page.
I will use DE for a single language site in german here as example:

pw_change-default-language__009.thumb.jpg.225a124c069eb17895cf5cb05b262b3a.jpg

 

Now I go to the ProcessWire online modules directory, down to the subsection for language packs and select
and download my desired (german) one: 

pw_change-default-language__010.thumb.jpg.755b7f9644080edb9d548b348022d492.jpg

 

pw_change-default-language__011.thumb.jpg.52e550006f97070c9b4e859013f20854.jpg

 

pw_change-default-language__012.thumb.jpg.19c4883d4d2e0be7ae6cbfaf207a3557.jpg

 

pw_change-default-language__013.thumb.jpg.55f4cebc4b5c94da37d6a73dd362f664.jpg

 

After downloading a lang pack as ZIP, I go back into my SETUP > LANGUAGES > default language page in admin,
select the downloaded lang pack ZIP and install it:

pw_change-default-language__014.thumb.jpg.1f10ef4f16c17e379f386ef01e08feb8.jpg

 

pw_change-default-language__015.thumb.jpg.2fc150e3c9d1ab6c2649fd8290f26e57.jpg

 

pw_change-default-language__017.thumb.jpg.7f84b2e81f41bcdda4042af11046a048.jpg

 

 

After the ZIP is uploaded, the files are extracted and installed, most of my screen is already in
the new default language. To get all fully switched, we save and leave that page, ...

pw_change-default-language__018.thumb.jpg.a37607ae2e2da189dc0709a18d5809ac.jpg

 

... and completely logout from the admin.

pw_change-default-language__019.thumb.jpg.56d5d07b246c8e7a98fb1b58d7f36fc8.jpg

 

Now, of course, we directly login back, ...

pw_change-default-language__021.thumb.jpg.df04b91ee8ead4e6699641890a56ff68.jpg

... and see, that now also the cached parts of the admin have switched to the new default language. ?

pw_change-default-language__022.thumb.jpg.8002c445925f5ef1125abe3c3c8463a1.jpg

 

That was it for a single language site in none english.

 

If you want to have a multi language site, just add more languages to the SETUP > LANGUAGES section.

When using a multi language site, I think you also want to use multi language input fields, and maybe different page names for your language page pendents. If so, you need to go into MODULES > CORE > filter LANGUAGE and install what you need or want to use of it, (if not already done).

Thanks for reading and happy coding, ?

 

  • Like 5
  • Thanks 3
Link to comment
Share on other sites

On 5/8/2020 at 1:06 PM, horst said:

Summary: When you start a new site and the default not should be english:

...

@horst, thank you very much for your post! Things could be so easy with a good tutorial ?

I think I'll try it this way. However, I've already put a lot of work into my site, but it isn't productive yet, so I think it isn't too late for a clean re-start with new fields and pages.

  • Like 2
Link to comment
Share on other sites

22 hours ago, FlorianA said:

Things could be so easy with a good tutorial

Hi Florian, I (temporary) have unhidden the post above yours with a walk through screenshot series. 

Have a good restart and fun with building your site! ?

  • Like 2
Link to comment
Share on other sites

On 5/8/2020 at 2:11 PM, bernhard said:
Quote

However, I noticed that it is a bad practice to modify the default language (english) with language files.
Instead you should add russian as an ADDITIONAL language and then set the guest user to this language (for the frontend) and also your admin user, so the PW admin is also in russian.

Maybe @dotnetic can elaborate why this is a bad practice?

@dotnetic any comment on this?

PS: Maybe you could link to that post in your language pack's readme ? 

  • Like 1
Link to comment
Share on other sites

@bernhard Yes, I was just about to write about it ?

I have reconsidered my statement, reviewed the procedure, and revoke the statement that it is bad practive. 

In my project there were some problems with languages at that time, but I can no longer reproduce them.

 I see no problems with the procedure described by Horst.

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

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
×
×
  • Create New...