Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to manage website languages programatically

Vote:
 

Hi,

Is it possible to enable/disable website languages in code not using Admin UI?

For example to disable 'sv' language which is enabled by create empty db script (EPiServerRelease75.sql).

 

#80684
Jan 29, 2014 16:43
Vote:
 

This is basically what EPiServer do in Admin Mode when activating languages:

var repository = LanguageBranch.LanguageBranchRepository;
LanguageBranch languageBranch = repository.Load("sv");
var copiedBranch = new LanguageBranch(languageBranch.ID, languageBranch.LanguageID, languageBranch.Name, languageBranch.SortIndex, languageBranch.RawIconPath, languageBranch.URLSegment, true);
repository.Save(copiedBranch);

#80689
Edited, Jan 29, 2014 23:44
Vote:
 

Aha. Interesting approach to bypass readonly "Enabled" property :). Thanks.

But it doesn't work in my code. I got "the wait operation timeout" on repository.Save(copiedBranch);

The same error I get when trying to languageBranch.Delete().

Do you have an idea why it works in Admin UI mode but doesn't work for me?

 

#80701
Jan 30, 2014 9:49
Vote:
 

It worked for me and I copied my code directly in my post.

Where/when are you trying to run your code?

#80702
Jan 30, 2014 9:51
Vote:
 

I run it from Initialization module on the site startup.
May be it is the reason?

[InitializableModule]
[ModuleDependency(typeof(InitializationModule))]

 

#80736
Jan 30, 2014 16:53
Vote:
 

That's exactly what I'm doing:

 

[InitializableModule]
[ModuleDependency(typeof(Web.InitializationModule))]
public class MyInitializer : IInitializableModule
{
private const string RouteName = "LogoutRedirect";

public void Initialize(InitializationEngine context)
{
var repository = LanguageBranch.LanguageBranchRepository;
var languageBranch = repository.Load("da");
var copiedBranch = new LanguageBranch(languageBranch.ID, languageBranch.LanguageID, languageBranch.Name, languageBranch.SortIndex, languageBranch.RawIconPath, languageBranch.URLSegment, true);
repository.Save(copiedBranch);

}

public void Preload(string[] parameters) { }

public void Uninitialize(InitializationEngine context)
{

}
}

#80752
Jan 31, 2014 8:23
Vote:
 

Thanks. The problem was on my side.

We do a set of operations (creating some initial content) using transactionScope and

repository.Save(copiedBranch) fails with timeout in the in the end of our scope
(which is completed succesfully without this language change).

 

#80774
Jan 31, 2014 14:50
Vote:
 

Great, hope you find a solution on the transactionScope issue.

#80775
Jan 31, 2014 14:55
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.