Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Setting the currentdocumentculture View modes: 
User avatar
Member
Member
gatsby0121 - 1/20/2012 11:30:44 AM
   
Setting the currentdocumentculture
I've created a separate aspx page, not through the portal, as per my previous post, but when I go to check the CMSContext.CurrentDocumentCulture, it's not set.

Is there something I need to call to set this?

User avatar
Member
Member
gatsby0121 - 1/20/2012 11:35:49 AM
   
RE:Setting the currentdocumentculture
I forgot to mention the reason I want to do this, in case this actually won't resolve it.

I have a culture UI string setup in administrator, and when I go to the page in french (?lang=fr-ca), it still returns the English version of the string.

User avatar
Member
Member
gatsby0121 - 1/20/2012 12:41:33 PM
   
RE:Setting the currentdocumentculture
Ok, so I realize why this isn't set, it's because it's a separate file that I've created in the system, using the kentico api, and as such, it's not a "Document".

So how can I use ResHelper.LocalizeString("{$Logon_Pages.CustomerHeader$}") to grab a resource string that I've added for french and english? It's grabbing the english version of the string, but not the french one.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 1/22/2012 10:19:02 PM
   
RE:Setting the currentdocumentculture
Hi,

I would like to recommend to add the custom strings via the user interface as described here. This will ensure they will be also exported if you will do so in the future. Or, then you can use the custom.resx file as well.

Best regards,
Juraj Ondrus

User avatar
Member
Member
gatsby0121 - 1/23/2012 4:27:58 AM
   
RE:Setting the currentdocumentculture
I think I might not have explained it correctly.

So I've already created custom strings as described in the link you sent (only in 5.5 r2) for everything else in the site as well, and that works fine, for the rest of the site.

The issue I'm having here though, is for the login pages (for customers only), I've created a "separate aspx page" outside of the portal system, but in the kenticocms folder, and it is using the kentico api.

Now, in the site, which the french language selected, using the language switcher, it grabs the french strings, created as per the link you provided, correctly.

But, when I then click on the login button, and it redirects me to the login page, that I've created outside of the cms, that is, as it's own aspx page residing in a folder in the kentico site directory (inetpub/wwwroot/KenticoCMS/sslFolder/logonpage.aspx). it only grabs the english version of the string, it's not resolving the french string, even though I'm using
/// <summary>
/// Gets or sets the HeaderText text
/// </summary>
public string HeaderText
{
get
{
return ResHelper.LocalizeString("{$Logon_Pages.CustomerHeader$}");
}
}


to set the actual string. So the question is, am I missing some sort of include, or am I not grabbing a session variable, which is preventing it from grabbing the french string?

that localize string is working in portal pages, but not in the separate aspx login page that I created.

User avatar
Member
Member
gatsby0121 - 1/23/2012 4:51:16 AM
   
RE:Setting the currentdocumentculture
I found the solution from another post of yours, I added this code and it works now:
// Set the culture
CurrentUserInfo ui = CMSContext.CurrentUser;
if (ui != null)
{
if ((ui.PreferredCultureCode != null) && (ui.PreferredCultureCode != ""))
{
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(ui.PreferredCultureCode);
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
}
}

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 2/24/2012 6:51:36 AM
   
RE:Setting the currentdocumentculture
Hi,
// Culture part
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(ui.PreferredCultureCode);


// E-mail part
UserInfoProvider.ForgottenEmailRequest(value, "Test", "LOGONFORM", "UserName") == "No user found." ? ResHelper.LocalizeString("Logon_Pages.NotFound") : ResHelper.LocalizeString("Logon_Pages.EmailSent");

In your code is the culture part configured based on UserInfo object. But in case you are requesting the new password, it means that current user does not exist (he do not know his password -> was not logged in and current user is actually public).

In this case is in Kentico used Default visitor culture (Site Manager - Sites - <site> - General tab). In case it is automatic the preferred culture from browser configuration is used.

In this case you could try to set the culture using:
string cultureUIdefault = CultureHelper.DefaultUICulture;

// or

CultureInfo ci = CultureInfoProvider.GetCultureInfo(CultureHelper.GetDefaultCulture(siteName));
string cultureDefault = ci.CultureCode;

// or

string defaultVisitorCulture = SiteInfo.DefaultVisitorCulture;

P.S. If it will not help please send an e-mail to support@kentico.com with information about your client.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
gatsby0121 - 2/24/2012 7:22:17 AM
   
RE:Setting the currentdocumentculture
This helps me to understand why the it's grabbing the default, but the last example you gave, doesn't actually set the culture, it only tells me what the default culture is, did you miss something?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 2/27/2012 6:47:35 AM
   
RE:Setting the currentdocumentculture
Here is the code which helps to solve this issue:
 protected void Page_Load(object sender, EventArgs e)
{
base.OnPreRender(e);

// Set the culture
CurrentUserInfo ui = CMSContext.CurrentUser;
if (ui != null)
{
if ((ui.PreferredCultureCode != null) && (ui.PreferredCultureCode != ""))
{
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fr-CA");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
}
}

}


/// <summary>
/// Retrieve the user password
/// </summary>
protected void Button1_Click(object sender, EventArgs e)
{
// Alternative code
//Label1.Text = ResHelper.GetAPIString("Webparts_Membership_RegistrationForm.rfvEmail", "fr-CA", "default Value");

string test = UserInfoProvider.ForgottenEmailRequest("notExistingUser@localhost.local", "CorporateSite", "LOGONFORM", "passwordrecovery@test.ca");

Label1.Text = (test == ResHelper.LocalizeString("{$logonform.nouser$}")) ? ResHelper.LocalizeString("{$Logon_Pages.NotFound$}") : ResHelper.LocalizeString("{$Logon_Pages.EmailSent$}");
}

The resource strings required by ForgottenEmailRequest method have to be translated in the appropriate resource file. In above example it is the resource string with a code name logonform.nouser.

Best regards,
Ivana Tomanickova