3

I want to localize a Component, and then edit some stuff in it.

function loadCompOnLocalize(e) {
  var localizedSeoComponent = e.source;
  if (localizedSeoComponent.isLocalized()) {//do stuff}
}

function loadCompOnLocalizeFailed(e) {//do other suff}

function seoComponentAfterLoad(component) {
  if (component.isLocalized()) {
    $log.debug("Component '{0}' is already localized.", childComponentId);
  } else {
    $evt.addEventHandler(component, "load", loadCompOnLocalize);
    $evt.addEventHandler(component, "loadfailed", loadCompOnLocalizeFailed);
    component.localize(true);
}

function seoComponentLoad(e) {
  $evt.removeEventHandler(e.source, "load", seoComponentLoad);
  $evt.removeEventHandler(e.source, "loadfailed", seoComponentLoadFailed);
  seoComponentAfterLoad(e.source);
};

function seoComponentLoadFailed(e) {
    $evt.removeEventHandler(e.source, "load", seoComponentLoad);
    $evt.removeEventHandler(e.source, "loadfailed", seoComponentLoadFailed);
    $log.debug("Failed to load seo component '{0}'", childComponentId);
};

if (childComponent.isLoaded()) {
  seoComponentAfterLoad(childComponent);
} else {
  $evt.addEventHandler(childComponent, "load", seoComponentLoad);
  $evt.addEventHandler(childComponent, "loadfailed", seoComponentLoadFailed);
  childComponent.load(true, $const.OpenMode.VIEW);
}

The problem is that when it enters loadCompOnLocalize, the Component returns false for .isLocalized().

On the configuration side: I have the Tridion.Web.UI.Core.Communicator disabled in configuration (because is like this in production). If is enabled, it works fine, because when it enters the handler for "load", the Component it has the correct value for isLocalized(). But when is disabled, there is no way I can check when the Component finished to be localized.

8
  • What version is this? I just tried the same on my local instance and it worked fine... Commented Dec 14, 2015 at 14:37
  • Any chance you're accidentally checking isLocalizable instead of isLocalized? That would indeed return false if it's already localized... Commented Dec 14, 2015 at 14:47
  • no, I am checking isLocalized() Commented Dec 14, 2015 at 14:53
  • Maybe you could post the full code? Or at least the smallest amount of code you can reproduce the issue with. Also please tag it with the version you are using :) Commented Dec 14, 2015 at 14:54
  • I added the rest of the code involved in loading the component and also some configuration settings. Commented Dec 14, 2015 at 15:08

1 Answer 1

2

Solved the problem with this workaround:

  1. Instead of loading the component to check if is localized, I used a sync call: tridion.Web.UI.ContentManager.General.GetItem(childComponentId, $const.OpenMode.VIEW, onSuccess, onFail, null, true). This is returning an xml from the server.

  2. onSuccess I checked the xml for the "tcm:IsLocalized" element and if true, localized the component with childComponent.localize(true);–

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.