Skip to content

Hard coded Strings Extraction

Kirill Stryaponov edited this page Sep 27, 2021 · 12 revisions

Supported

  • Vue templates,
  • JSX templates,
  • HTML files.

File types supported: vue, js, ts, jsx, tsx

Extraction UI (TODO Screenshots of triggers and before/after result)

Strings could be ignored within file and within the project from a quick fix menu.

i18n Ally hardcoded string extraction UI

Commands

i18n-ally.detect_hard_strings (expiremental) Detect hard-coded strings in the current file

Configuration options (document enabledFrameworks: at least general)

// Parser options for extracting HTML, see https://github.com/lokalise/i18n-ally/blob/master/src/extraction/parsers/options.ts
"i18n-ally.extract.parsers.html": {
    "attributes": ["text", "title", "alt", "placeholder", "label", "aria-label"],
    "ignoredTags": ["script", "style"],
    "vBind": true,
    "inlineText": true
},

// Enables hard-coded strings detection automatically whenever opening supported a file
"i18n-ally.extract.autoDetect": false,

// Make sure that particular refactoring templates would be picked up be the bulk extraction depending on the context
"i18n-ally.refactor.templates": [
   {
     // affect scope (optional)
     // see https://github.com/lokalise/i18n-ally/blob/master/src/core/types.ts#L156-L156
     "source": "html-attribute",
     "templates": [
       "i18n.t('{key}'{args})",
       "custom.t('{key}'{args})",
     ],
     // accept globs, resolved to project root (optional)
     "include": [
       "src/**/*.{vue,ts,js}",
       "index.html"
     ],
     "exclude": [
       "src/config/**"
     ]
   },
   // ...
]