JS delle App di Crowdin

La JS delle App di Crowdin è una libreria creata per una più facile interazione con Crowdin Imprese. Since the integration uses the iframes, there are certain limitations on the interaction between windows: environments are encapsulated and do not have access to the page content, code, styles, and any other information related to the page.

The Crowdin Apps JS library is based on cross-window messaging technology and uses postMessage() to interact between multiple windows.

Per iniziare

To use this library, connect it on the module page by inserting the following code into the page header:

<script src="https://cdn.crowdin.com/apps/dist/iframe.js"></script>

After adding the code mentioned above, you’ll be able to use the global AP variable.

Note! Don't download the iframe.js file and serve it up from your app server directly. Il file iframe.js dev'esser servito da Crowdin Imprese per stabilire il ponte di messaggistica tra domini. Il file iframe.js è inteso solo per l'uso in un iframe in Crowdin Imprese e non funziona per pagine web indipendenti.

Global Actions

Global actions are the actions that are available on all module pages.

AP.getContext(callback)

The method retrieves the context information about the current page and puts it into the callback. For example, the project ID where the module is opened or the locale used on the page.

Esempio:

  AP.getContext(function(contextData) {
    console.log("Object: context", contextData);
  });

Properties:

callback

Type: function

Description: The callback that handles the response object.

AP.getJwtToken(callback)

The method retrieves a JWT token string. Used to get a current token. If the previous token has a validity period of less than one minute, the method will generate and return a new token.

Esempio:

  AP.getJwtToken(function(jwtToken) {
    console.log("String: JWT token", jwtToken);
  });

Properties:

callback

Type: function

Description: The callback that handles the response string.

Editor Module Actions

Editor module actions provide a possibility to get information from the Editor UI. These actions are available only on pages that are loaded in an iframe in the Editor-panels module.

AP.editor.getString(callback)

The method retrieves information about the currently selected string in the Editor.

Esempio:

  AP.editor.getString(function(stringData) {
    console.log("Object: source string", stringData);
  });

Properties:

callback

Type: function

Description: The callback that handles the response object.

AP.editor.getTranslations(callback)

The method retrieves a list of translations suggested to the currently selected string in the Editor. Additionally, the response contains information about the translation author, the number of votes, and approval on the current workflow step.

Esempio:

  AP.editor.getTranslations(function(translationsData) {
    console.log("Array: translation objects", translationsData);
  });

Properties:

callback

Type: function

Description: The callback that handles the response array.

AP.editor.getTopTranslation(callback)

The method retrieves a top translation (the translation with the highest priority) for the currently selected source string in the Editor.

Esempio:

  AP.editor.getTopTranslation(function(topTranslationData) {
    console.log("Object: top translation", topTranslationData);
  });

Properties:

callback

Type: function

Description: The callback that handles the response object.

Event Module Actions

Le azioni del modulo dell’evento forniscono una possibilità di lavorare con gli eventi, consentendo all’app di Crowdin di rispondere agli eventi che si verificano nell’UI di Crowdin Imprese e innescare i propri eventi.

AP.events.once(event, callback)

The method subscribes a one-time listener to detect events with a specified name. The listener is unsubscribed as soon as the first event is processed.

Esempio:

  AP.events.once("event", function(eventData) {
    console.log("Event data", eventData);
  });

Properties:

event

Type: string

Description: The name of the event the callback of the function should react to.

callback

Type: function

Description: The callback that handles the event. Depending on the event's type, there could be either one or a few arguments in the callback.

AP.events.on(event, callback)

The method subscribes a listener to all events with a specified name.

Esempio:

  AP.events.on("event", function(eventData) {
    console.log("Event data", eventData);
  });

Properties:

event

Type: string

Description: The name of the event the callback of the function should react to.

callback

Type: function

Description: The callback that handles the event. Depending on the event's type, there could be either one or a few arguments in the callback.

AP.events.off(event, callback)

The method unsubscribes a listener for an event with a specified name.

Esempio:

  function callback(eventData) {
    console.log("Event data", eventData);
  };

  AP.events.on("event", callback);
  AP.events.off("event", callback);

Properties:

event

Type: string

Description: The name of the event the callback of the function should be unsubscribed from.

callback

Type: function

Description: The callback that was previously subscribed to the event.

AP.events.ofAll(event)

The method unsubscribes all previously subscribed listeners from the specified event.

Esempio:

  AP.events.offAll("event");
event

Type: string

Description: The name of the event all listeners should be unsubscribed from.

AP.events.onAny(callback)

Il metodo si iscrive a tutti gli eventi dall’UI di Crowdin Imprese.

Esempio:

  AP.events.onAny(function(event, data) {
    console.log("Event name string", event);
    console.log("Event data", data);
  });

Properties:

callback

Type: function

Description: The callback that receives the name of the event and all the data transferred to the event.

AP.events.offAny(callback)

The method unsubscribes a listener from all events.

Esempio:

  function callback(event, data) {
    console.log("Event name string", event);
    console.log("Event data", data);
  };

  AP.events.onAny(callback);
  AP.events.offAny(callback);

Properties:

callback

Type: function

Description: The callback that was subscribed to all events.

Questo articolo è stato utile?