npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ui5-i18n-validator

v0.2.4

Published

Checking translations for UI5 applications

Downloads

194

Readme

Checking i18n files in UI5

i18n files are used in SAPUI5 for translating applications. Per language one file is created, containing key-value-pairs (see documentation), see example:

showHelloButtonText=Say Hello
helloMsg=Hello {0}

This tool helps to validate those files.

CLI Usage

To check the i18n files of an application, just call the validator in your applications directory:

Usage: ui5-i18n-validator [options]

Options:
   --bail-on-error, -b     Cancel npm task, if any errors were found [boolean]
   --rules, -r             List of rules, seperated by space [string]

As best practice is, that the i18n-files are located in a dedicated i18n directory, the directories must be organized like this:

App directory
 ├─ dist
 └─ webapp
   ├─ controller
   ├─ i18n
   │   ├─ i18n.properties
   │   ├─ i18n_de.properties
   │   ├─ i18n_en.properties
   │   ├─ ...
   ├─ view

Maybe in further versions, and if requested, the path to i18n directory can be configured.

Options

bail-on-error

ui5-i18n-validator --bail-on-error will exit the process with error code 1.

Hint: This can be helpful, for example in CI/CD scenarios, when you want the build process to fail, if there are errors.

If the parameter is not provided, the process will end with no error code (0).

rules

ui5-i18n-validator --rules missing-keys empty-keys will only check the two rules, which are provided as parameter.

Following rules exist:

  • missing-keys
  • empty-keys
  • hardcoded-texts

For a detailed description of the rules see chapter Validation rules.

If the parameter is not provided, all rules will be used for validation.

Validation rules

Currently following rules are supported for validating translations:

Missing keys

This rule checks, if there are keys defined for one language, which are missing for another. For example:

i18n_en.properties:

formTitle = Form
sendBtn = Send

i18n_de.properties:

formTitle = Formular

In this case the validator will print the following content on CLI:

Checking missing keys:
‼ Following keys exist in *en* but are missing in *de*
   ×  sendBtn

If there's no key missing, the output will look like this:

Checking missing keys:
√ No missing keys found.

Empty keys

This rule will check if there are keys defined, missing a value. For example:

i18n_en.properties:

formTitle = Form
sendBtn = 

In this case, the validator will print a message like this:

Checking empty keys:
‼ Following keys are empty in en
   × sendBtn

In case there's no value missing, the output will look like this:

Checking empty keys:
√ No empty keys found.

Hardcoded texts

Basically this rule checks all xml files in the webapp folder for attributes, which should be translated (for a complete list of attributes see Chapter Limitations). If an attributes value does not start with an {, the validator assumes, that it's not translated. So:

<!-- This would be an error -->
<Page title="View 1" id="page">

<!-- This would be fine -->
<Page title="{i18n>viewTitle}" id="page">

If there are hardcoded texts, the output will look like this:

Checking hardcoded texts:
‼ Following propably hardcoded texts were found in View1.xml
   ×  line: 9    attribute: title        value: View 1

In case there are no hardcoded texts found, the output will look like this:

Checking hardcoded texts:
√ No hardcoded texts found.

Limitations

Ensuring that there are definitely no hardcoded texts, can be very complex. So there are some limitations:

  • Only xml files are checked. So hardcoded texts from JavaScript files won't be found (e.g. MessageBox.show("hello world"))
  • Only some xml attributes are currently checked, wheter they are hardcoded or not. As of now, the following attributes are checked:
    • title,
    • subtitle,
    • text,
    • placeholder,
    • headerText,
    • objectTitle,
    • objectSubtitle,
    • secondTitle,
    • label

Contribute

Would be great if you contribute. There's lots of room for improvement. See CONTRIBUTING.md.

License

MIT © Lukas Böhm