Try our conversational search powered by Generative AI!

Language - Inherit settings from the parent page - disable programatically

Vote:
 

Hi,

Regarding the language fallback for a page, ( as mentioned here in your user guide ) can I disable it programatically?

My site has 2 languages, en-NZ and en-AU.

I have a scheduled job that adds 'ProductPage' content under a 'CategoryPage'. I need the parent page (CategoryPage) to be in en-AU and this needs to be the fallback language for en-NZ. Product pages created under it need to be available in either Australia (en-AU) or New Zealand (en-NZ), or both.

My problem is that each 'ProductPage' is getting created with language settings marked as 'Inherit settings from the parent page', so products that are not available in en-NZ are allowed to fallback to en-AU... but I don't want this.

Is there a way to prevent a page from inheriting its fallback language (without unticking it in the cms)?

I appreciate any help

Thanks

Dan

#210357
Edited, Nov 21, 2019 12:04
Vote:
 

Looks like I may have solved this by setting

productPage.MasterLanguage = null;
#210372
Nov 21, 2019 12:43
- Nov 21, 2019 13:06
Haha.. you beat me! nice find.
Vote:
 

Hey Dan,

Check out MasterLanguage and MasterLanguageBranch in the PageData class which your ProductPage would be inheriting https://world.episerver.com/documentation/class-library/?documentId=cms/7/b38e303b-a955-4dc6-4bd0-d954c4815ea2

#210391
Edited, Nov 21, 2019 13:06
Vote:
 

This kinda worked... but pages that were not published in NZ were 'falling back' to AU.

I was able to prevent the page from 'falling back' by updating:

var languageSpecificProductPage =  _contentRepository.CreateLanguageBranch<ProductPage>(content, new LanguageSelector("en-NZ"));

to:

var languageSpecificProductPage = _contentRepository.CreateLanguageBranch<ProductPage>(content, LanguageSelector.Fallback(preferredLanguageBranch: language.Name, enableMasterLanguageFallback: false));
#210413
Nov 22, 2019 3:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.