Export Localizable Elements for Bulk Localization Title

To speed up the localization process, configure localization export and import using two API jobs.

To start, you must create a custom job step (referred to as FindPages in the following documentation) that provides a list of PageIDs to be exported. The localization export only exports attributes of the types STRING, TEXT and MARKUP, and skips other types. For additional information on this process, refer to Creating Custom Job Steps.

The following code samples are supplied for reference:

FindPages.js

/**
* Sample logic for finding Page Designer pages for bulk translation
*
* @module cartridge/scripts/jobsteps/FindPages
*/

'use strict';

/**
* Find the pages main function
*
* @param {object}  parameters Job step parameters
* 
* @param {boolean} parameters.IsDisabled Mark the step as disabled - skips step execution and returns an OK status
* @param {string}  parameters.TranslationContentFolder The content folder for pages for translation
* @param {string}  parameters.OutputPageIDsFile File with list of IDs of pages found for translation, relative to the 'Impex/src' folder
* @param {boolean} parameters.OutputUnassignmentFile File with unassignments for the Page Designer pages from the translation folder, relative to the 'Impex/src' folder, not created if omitted
* @param {string}  parameters.NoDataFoundStatus No Data for translation found exit code
* 
* @param {dw.job.JobStepExecution} stepExecution Represents an execution of a step that belongs to a job
* 
*/
function DoFindPages(parameters, stepExecution) {
	var 
		Status = require("dw/system/Status"), 
		ContentMgr = require("dw/content/ContentMgr"),
		File = require("dw/io/File"),
		FileWriter = require("dw/io/FileWriter");
	
	var folder, foundContent, content, contentFolder, impexsrc, pageidsFile, pageidsWriter, unassign, unassignFile, unassignWriter;
	
	if (parameters.IsDisabled) {
	    return new Status(Status.OK, "SKIPPED", "The job step " + stepExecution.stepID + " was skipped");
	}
	
	folder = ContentMgr.getFolder(parameters.TranslationContentFolder); // get contents of translation folder
	foundContent = (folder != null) && (folder.content.length > 0);
	if (foundContent) {
		foundContent = false;
		impexsrc = new File('IMPEX/src');
		pageidsFile = new File(impexsrc, parameters.OutputPageIDsFile);
		pageidsWriter = new FileWriter(pageidsFile, "UTF-8");
		unassign = !!parameters.OutputUnassignmentFile;
		if (unassign) {
			unassignFile = new File(impexsrc, parameters.OutputUnassignmentFile);
			unassignWriter = new FileWriter(unassignFile, "UTF-8");
			unassignWriter.writeLine('<?xml version="1.0" encoding="UTF-8"?>');
			unassignWriter.writeLine('<library xmlns="http://www.demandware.com/xml/impex/library/2006-10-31" library-id="' + ContentMgr.siteLibrary.ID +'">');
		}
		for (var i=0; i<folder.content.length; i++) { // loop through the folder content
			content = folder.content[i];
			if (content.page) {
				foundContent = true;
				pageidsWriter.writeLine(content.ID); // write page ID to the result pages list file
				if (unassign) {
					unassignWriter.writeLine('  <content content-id="' + content.ID + '">'); // write content xml for unassigning the page from the translation folder
					unassignWriter.writeLine('    <folder-links>');

					for (var j=0; j<content.folders.length; j++) {
						contentFolder = content.folders[j];
						unassignWriter.write('      ');    
						if (contentFolder.ID == folder.ID) { // as it is not possible to just delete a folder assignment, all folders a listed without the translation one
							unassignWriter.write('<!-- ');   // an XML comment is used to not include the translation folder, but it is also possible to omit it in the content xml
				        }
						if (contentFolder.ID == content.classificationFolder.ID) {
							unassignWriter.write('<classification-link folder-id="'+contentFolder.ID+'"/>')
						} else {
							unassignWriter.write('<folder-link folder-id="'+contentFolder.ID+'"/>')
						}
						if (contentFolder.ID == folder.ID) {
							unassignWriter.write(' -->');
				        }
						unassignWriter.writeLine('');
					}
					unassignWriter.writeLine('    </folder-links>');
					unassignWriter.writeLine('  </content>');
				}
			}
		}
		pageidsWriter.flush();
		pageidsWriter.close();
		if (unassign) {
			unassignWriter.writeLine('</library>');
			unassignWriter.flush();
			unassignWriter.close();
		}
	}
	if (!foundContent) {
		return new Status(Status[parameters.NoDataFoundStatus], "NO_DATA_FOUND", "No pages were found for translation in folder " + parameters.TranslationContentFolder)
	}
}


/* Exports of the modules */
/**
* @see {@link module:cartridge/scripts/jobsteps/FindPages~DoFindPages} 
*/
exports.DoFindPages = DoFindPages;

steptypes.json

{
	"step-types": {
		"script-module-step": [{
			"@type-id": "custom.PageDesignerTranslate.FindPages",
			"@supports-site-context": "true",
			"@supports-organization-context": "false",
			"module": "bc_page_designer_translate/cartridge/scripts/jobsteps/FindPages.js",
			"description": "Find Page Designer Pages for translation",
			"function": "DoFindPages",
			"parameters": {
				"parameter": [{
						"@name": "IsDisabled",
						"description": "Mark the step as disabled - skips step execution and returns an OK status",
						"@type": "boolean",
						"@required": false,
						"@trim": true
					},
					{
						"@name": "TranslationContentFolder",
						"description": "The content folder for pages for translation",
						"@type": "string",
						"@required": "true",
						"@trim": "true",
						"default-value": "for_translation"
					},
					{
						"@name": "OutputPageIDsFile",
						"description": "File with list of IDs of pages found for translation, relative to the 'Impex/src' folder",
						"@type": "string",
						"@required": "true",
						"@trim": "true",
						"default-value": "library/page_ids.txt"
					},
					{
						"@name": "OutputUnassignmentFile",
						"description": "File with unassignments for the Page Designer pages from the translation folder, relative to the 'Impex/src' folder, not created if omitted",
						"@type": "string",
						"@required": "false",
						"@trim": "true"
					},
					{
						"@name": "NoDataFoundStatus",
						"@type": "string",
						"@required": true,
						"@trim": true,
						"enum-values": {
							"value": [
								"OK",
								"ERROR"
							]
						},
						"default-value": "OK",
						"description": "No Data for translation found exit code"
					}

				]
			},
			"status-codes": {
				"status": [{
						"@code": "ERROR",
						"description": "Used when an error occurred."
					},
					{
						"@code": "OK",
						"description": "Used when execution was successful."
					},
					{
						"@code": "NO_DATA_FOUND",
						"description": "Used when no page designer pages could be found in the source folder."
					},
					{
						"@code": "SKIPPED",
						"description": "Used when step is marked as disabled."
					}
				]
			}
		}]
	}
}

Export Localizable Elements Using Folders

Speed up your localization process by defining pages in need of bulk translation. There are multiple ways to do this, such as manually creating a file containing the page IDs in JSON string format, but the simplest method is to assign pages to a dedicated content folder through Business Manager.

Create a folder for the pages you want to localize.
  1. In Business Manager select Merchant Tools > site > Content > Page Designer.
  2. For each page you want translated, open the action menu by clicking the arrow at the end of the line.
  3. Click Add to Folder.
  4. Select the appropriate folder for translation and click Next. Then click Save & Close.

Export Elements for Bulk Localization

To speed up the localization process, export the localizable elements of one or more pages with custom jobs.

Before exporting any elements for localization, you must have a clear definition of which pages are to be localized.
  1. To create a new job in Business Manager, select Administration > Operations > Jobs, and click New Job.
  2. Click the newly created job, and click the Schedule and History tab. Set the necessary interval you want the job to run.
  3. Click the Job Steps tab.
    There are four steps for this job:
    1. FindPages - Looks for all the pages in the defined folder created for localization, and generates two output files used in the bulk localization process.
    2. ExportPageLocalization -Creates the export page file.

      Configure the ExportPageLocalization export set with the file name of the file created by the custom job step.

      We recommend you use a Resource file type, but coordinate with your localization team to determine which file type to use.
      Note: If you set a locale, the export uses date from that locale. If no locale is set, your default locale is used.
    3. ImportPageUnassignments - This job step imports content. Set ImportMode to merge.
    4. FtpUpload - A custom job step that uploads the content to be localized.
  4. Run the job manually, by clicking Run Job, or coordinate with your merchandisers and localization team to schedule it.
    The pages are exported in a .zip file containing one file for each page.
  5. Provide the content to your organizations localization team. You can automate this process through a custom job step.
    Keep in mind that the text in the files doesn’t necessarily appear in the order it does on the page. We recommend you attach a URL, screen shot, or other method of providing context when handing off the files.
  6. Localize the content using your organization’s localization process.

Import Elements for Bulk Localization

To speed up the localization process, import the localized elements of one or more pages with custom jobs.

Before importing your localized elements, verify the location and existence of the files you will be importing.
  1. To create a new job in Business Manager, select Administration > Operations > Jobs, and click New Job.
  2. Click the newly created job, and click the Schedule and History tab. Set the necessary interval you want the job to run.
  3. Click the Job Steps tab.
    There are two steps for this job:
    1. FtpDownload

      A custom job step that downloads the localized content.

    2. ImportPageLocalization

      The default filename this job looks for is translation.zip. To change this, you must create an additional step to rename it based on your configurations.

  4. Run the job manually, by clicking Run Job, or coordinate with your merchandisers and localization team to schedule it.