Skip to content

Latest commit

 

History

History
699 lines (502 loc) · 8.35 KB

require-localize-metadata.md

File metadata and controls

699 lines (502 loc) · 8.35 KB

@angular-eslint/require-localize-metadata

Ensures that $localize tagged messages contain helpful metadata to aid with translations.

  • Type: suggestion

Rule Options

The rule accepts an options object with the following properties:

interface Options {
  requireDescription?: boolean;
  requireMeaning?: boolean;
}

Usage Examples

The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit.


❌ - Toggle examples of incorrect code for this rule

Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`Hello i18n!`;
                               ~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

const localizedTexts = {
  helloI18n: $localize`:An introduction header for this sample:Hello i18n!`
};
localizedTexts.helloI18n = $localize`Hello i18n!`;
                                    ~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

return $localize`Hello i18n!`;
                ~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

someFunction($localize`Hello i18n!`);
                      ~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:site header|:Hello i18n!`;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:@@custom_id:Hello i18n!`;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:site header|@@custom_id:Hello i18n!`;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireMeaning": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`Hello i18n!`;
                               ~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true,
        "requireMeaning": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:An introduction header for this sample:Hello i18n!`;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireMeaning": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:|An introduction header for this sample:Hello i18n!`;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true,
        "requireMeaning": true
      }
    ]
  }
}

❌ Invalid Code

const localizedText = $localize`:Hello i18n!`;
                               ~~~~~~~~~~~~~~



✅ - Toggle examples of correct code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error"
    ]
  }
}

✅ Valid Code

const localizedText = $localize`Hello i18n!`;



Default Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error"
    ]
  }
}

✅ Valid Code

const localizedText = $localize`:site header|:Hello i18n!`;



Default Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error"
    ]
  }
}

✅ Valid Code

const localizedText = $localize`:@@custom_id:Hello i18n!`;



Default Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error"
    ]
  }
}

✅ Valid Code

const localizedText = $localize`:site header|@@custom_id:Hello i18n!`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

✅ Valid Code

let localizedText = $localize\`:An introduction header for this sample:Hello i18n!\`;
localizedText = $localize\`:An introduction header for this sample modified:Hello i18n modified!\`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

✅ Valid Code

const localizedTexts = {
  helloI18n: $localize\`:An introduction header for this sample:Hello i18n!\`
};
localizedTexts.helloI18n = $localize\`:An introduction header for this sample modified:Hello i18n modified!\`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

✅ Valid Code

return $localize\`:An introduction header for this sample:Hello i18n!\`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

✅ Valid Code

someFunction($localize\`:An introduction header for this sample:Hello i18n!\`);



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true
      }
    ]
  }
}

✅ Valid Code

const localizedText = \`Hello i18n!\`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireMeaning": true
      }
    ]
  }
}

✅ Valid Code

const localizedText = $localize\`:site header|:Hello i18n!\`;



Custom Config

{
  "rules": {
    "@angular-eslint/require-localize-metadata": [
      "error",
      {
        "requireDescription": true,
        "requireMeaning": true
      }
    ]
  }
}

✅ Valid Code

const localizedText = $localize\`:site header|An introduction header for this sample:Hello i18n!\`;