Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement web-types (JetBrains) for the i18n-t component #874

Open
3 tasks done
santiagoarizti opened this issue Jan 11, 2022 · 2 comments
Open
3 tasks done

Implement web-types (JetBrains) for the i18n-t component #874

santiagoarizti opened this issue Jan 11, 2022 · 2 comments
Labels
🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments

Comments

@santiagoarizti
Copy link

Clear and concise description of the problem

I use phpstorm as my IDE, and it helps detect missing html tags and/or vue components in vue SFCs.

Problem is, phpstorm (or webstorm) doesn't recognize the tag <i18n-t keypath="...">....

See discussion here that I started to find a solution to this problem:
#872

See jetbrains official documentation:
https://github.com/JetBrains/web-types

Suggested solution

In order to have autocomplete, we need to implement this simple feature in the package.json of the npm package

...
"web-types": "./web-types.json",
...

and in the web-types.json file this is a sample content that will take care of the <i18n-t> tag:

{
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
  "framework": "vue",
  "name": "vue-i18n",
  "version": "9.1.9",
  "contributions": {
    "html": {
      "types-syntax": "typescript",
      "description-markup": "markdown",
      "tags": [
        {
          "name": "I18nT",
          "description": "built-in component from vue-i18n",
          "doc-url": "https://vue-i18n.intlify.dev/",
          "attributes": [
            {
              "name": "plural",
              "description": "Determines if use count 0, 1 or many",
              "default": "'0'",
              "value": {
                "kind": "expression",
                "type": "string"
              }
            },
            {
              "name": "keypath",
              "description": "The ident of the lang to be used",
              "default": "'santi'",
              "value": {
                "kind": "expression",
                "type": "string"
              }
            }
          ],
          "slots": [
            {
              "name": "default",
              "description": "interpolated string"
            }
          ]
        }
      ]
    }
  }
}

Obviously this schema is fine for my own project, I would clean the descriptions and perhaps add more features as described in the official documentation.

But this does the job fine and is a very straightforward solution.

Alternative

An alternative would be to allow to import the <i18n-t> component from 'vue-i18n'; which in theory would allow the IDE to find the definition of the component as well. This would work for more IDEs, but would require more lines of code.

See example

<script>
// the second import here is the component
import {useI18n, I18nT} from 'vue-i18n';

export default {
  components: {
    'i18n-t': I18nT, // note that in <script setup> this line is not necessary
  },
}
</script>
<template>
  <i18n-t keypath="hello">
    <strong>world</strong>
  </i18n-t>
</template>

Additional context

This is the working solution in my local development environment

image

I recommend to add this to the npm package so that everyone can get good linting in phpstorm or any other jetbrains IDE

Validations

@santiagoarizti santiagoarizti added the Status: Proposal Request for comments label Jan 11, 2022
@kazupon kazupon added the Status: PR Welcome Welcome to Pull Request label Jan 13, 2022
Copy link
Member

kazupon commented Jan 13, 2022

@santiagoarizti
Thank you for your proposal!
That sounds good to me!

I think your suggestion is great because it can support for JetBrains to handle it without having to modify vue-i18n-next.

PR will be welcome 😃

@kazupon kazupon added the 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing label Nov 15, 2022 — with Volta.net
@6XGate
Copy link

6XGate commented Mar 23, 2023

This is a more complete definition for the i18n-t component. The others should be added.

{
    "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
    "framework": "vue",
    "name": "vue-i18n",
    "version": "9.1.9",
    "contributions": {
        "html": {
            "types-syntax": "typescript",
            "description-markup": "markdown",
            "tags": [
                {
                    "name": "I18nT",
                    "description": "built-in component from vue-i18n",
                    "doc-url": "https://vue-i18n.intlify.dev/",
                    "attributes": [
                        {
                            "name": "plural",
                            "description": "Determines if use count 0, 1 or many",
                            "default": "0",
                            "value": {
                                "kind": "expression",
                                "type": ["string", "number"]
                            }
                        },
                        {
                            "name": "keypath",
                            "description": "The ident of the lang to be used",
                            "default": "'santi'",
                            "value": {
                                "kind": "expression",
                                "type": "string"
                            }
                        },
                        {
                            "name": "tag",
                            "description": "The tag into which to render the result",
                            "default": "span",
                            "value": {
                                "kind": "expression",
                                "type": "string"
                            }
                        },
                        {
                            "name": "locale",
                            "description": "The locale to use",
                            "default": "en",
                            "value": {
                                "kind": "expression",
                                "type": "string"
                            }
                        },
                        {
                            "name": "scope",
                            "description": "The component scope",
                            "default": "parent",
                            "value": {
                                "kind": "expression",
                                "type": "string"
                            }
                        },
                        {
                            "name": "i18n",
                            "description": "The i18n instance",
                            "default": "null",
                            "value": {
                                "kind": "expression",
                                "type": "string"
                            }
                        }
                    ],
                    "slots": [
                        {
                            "name": "<name>",
                            "pattern": {
                                "items": "argument",
                                "template": [
                                    "#item:argument"
                                ]
                            },
                            "argument": {
                                "name": "Argument",
                                "pattern": {
                                    "regex": ".+"
                                },
                                "doc-hide-pattern": true
                            },
                            "description": "Slot to provide a named value",
                            "doc-url": "https://vue-i18n.intlify.dev/guide/advanced/component.html#slots-syntax-usage"
                        }
                    ]
                }
            ]
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants