I'm new to Sitecore and I have an issue while trying to retrieve item/s by specific language by the following steps:
- Added new language for an item through the content editor which (i.e "ar" and culture info is "ar-AE" )
get the language by either of following (both fails):
SC.Globalization.Language lang = SC.Globalization.Language.Parse("ar-AE");
// and tried by replacing culture with ("ar")SC.Globalization.Language lang = SC.Data.Managers.LanguageManager.GetLanguage("ar-AE");
// and also tried by replacing culture with ("ar")
SC.Context.SetLanguage(lang, true);
The Response: I'm able to get only "en" items and when I change the language (by the above mentioned code), items are retrieved properly but fields are empty.
Note: I've checked Sitecore DB Master -> VersionedFields[Language] and found the other languages of the same item saved as "ar-AE" (only single item version is used)
Update:
I'm using filter to change the whole API language by the following code:
public class LanguageChecker : System.Web.Mvc.ActionFilterAttribute
{
// Set Default Language
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
SC.Globalization.Language lang = SC.Data.Managers.LanguageManager.GetLanguage("en");
if (filterContext.HttpContext.Request.Headers["Accept-Language"] != null || filterContext.HttpContext.Request.Headers["Accept-Language"].ToLower() == "ar")
{
// lang = SC.Globalization.Language.Parse("ar");
lang = SC.Data.Managers.LanguageManager.GetLanguage("ar-AE");
}
SC.Context.SetLanguage(lang, true);
base.OnActionExecuting(filterContext);
}
}
and annotated this filter in the API Main Controller (just like any filter)
So, I'm calling the item by:
SC.Data.Items.Item item = context.GetItem(SC.Data.ID.Parse(id));
- in this case I don't have to change the language for each item.