Documentation section

File Format - Javascript

Learn how to use Localazy CLI for app and software localization with translations in Javascript files.

You can use Localazy to directly localize Javascript files with various formats supported, and with a configurable parser based on our JSON support.

The format 🔗

Our parser can adapt to many formats of JS files that follow the rule PREFIX { localizable content } SUFFIX such as the examples below.

Please note that functions, imports, lambdas, explicit types (for TypeScript), string concatenation, etc. are not supported in the localizable content part. Also, there can be only one localizable part in the file.

For multiline strings, you can use backticks.

export default {
  parent1: {
    // Comment is used as a context information for translator.
    child_1: "Text 1",
    child_2: "Text 2",
    child_3: "Text 3",
  },
  parent2: {
    ...
  } 
};

var translations = {
  parent: {
    child: "Text 1"
  }
}

define({
  parent: {
    child: "Text 1"
  }
});

Forcing double quotes 🔗

By default, the variable names are not double-quoted. We only use double quotes when the variable name contains unsupported characters to prevent issues with the generated file.

You can add force_quotes to the features in the upload section to force using double quotes for all variable names.

Available features 🔗

All features supported by Localazy for JSON are available including plurals, arrays, multilingual files, etc. Only the support for requirejs is not available.

Context information 🔗

It’s possible to use comments. They are parsed and stored as context information for translators.

export default {
  
  // Please keep translation short.
  short_name: "Short Name",

  /*
  Multi-line comments are allowed as well.
  */
  long_name: "Long Name"

};

Filtering untranslated strings 🔗

By default, when the output file is generated, Localazy uses texts from the source languages when the translation in the exported language is missing.

This approach is safeguarding you from missing keys that can lead to crashes in some solutions/frameworks.

This feature can be disable by adding filter_untranslated to features in the upload section and reuploading your source language file.