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

Localize messages support #252

Open
azu opened this issue Dec 26, 2016 · 7 comments
Open

Localize messages support #252

azu opened this issue Dec 26, 2016 · 7 comments
Labels
Status: Proposal Request for comments

Comments

@azu
Copy link
Member

azu commented Dec 26, 2016

stylelint support reporting custom message that is defined by user.

{
  "color-hex-case": [ "lower", {
    "message": "Lowercase letters are easier to distinguish from numbers"
  } ],
  "indentation": [ 2, {
    "ignore": ["block"],
    "message": "Please use 2 spaces for indentation. Tabs make The Architect grumpy.",
    "severity": "warning"
  } ]
}

This feature is needed for textlint.
Because, I know that textlint is used in some web application and software.
These application require "custome message" feature I think.

Can someone has implementation idea?


Update(2018-01-21):

Goal

Primary, We want to support following cases.

  • Localize messages
    • textlint should have Internationalisation(i18n) system
  • Custom messages by textlint application user
    • Application user can modify message
    • For example, an app that use textlint can customize report message.
  • improve message test by textlint-tester
  • (Optional) Lint messages by textlint-tester
    • Lint error message
    • message should be start capitalized?
    • We want to prepare minimal pattern as recommendation
Optional(if it is as possibe)
@azu azu added the Idea label Dec 26, 2016
@azu
Copy link
Member Author

azu commented Mar 21, 2017

I think that a casual User not needed custome message.
But, i18n/L10n message help user to read error message.

I propose that

  • The user define your local like en-US, ja-JP in .textlintrc
    • If the local is not defined, use os-locale by default.
  • textlint pass the locale information to a rule via context object
  • The rule can localize message by the locale.
    • textlint-rule-helper help the localization.

It is very small start.

@azu
Copy link
Member Author

azu commented Mar 21, 2017

📝 textlint will provide custom message by custom plugin/settings, maybe

{
    "localize":{
       "rule-a": {
          "message-id": "localized message"
       }
    },
    {
	"rules": {
    	    "rule-a": true
        }
    }
}

@azu azu added Status: Proposal Request for comments and removed Status: Proposal Request for comments Idea labels May 17, 2017
@azu
Copy link
Member Author

azu commented Jan 21, 2018

markuplint has localize function.

const message = await messages(locale, 'error');

@azu azu changed the title Custom messages support Localize messages support Jul 15, 2018
@azu
Copy link
Member Author

azu commented Jul 15, 2018

I have thought about it and meta data for rule.

src/
- textlint.meta.json
- rule.js

textlint.meta.json:

{
  "messages": {
     "id-a": "message a {key}",
     "id-b": {
       "ja": "メッセージ B",
       "en": "Message B"
      }
   }
}

rule.js:

const meta = require("./textlint.meta.json");
export default function(context) {
    const { RuleError, localize, report} = context;
    return {
        [context.Syntax.Str](node) {
            const message = localize(meta.messages["id-a"], { key: "value"});
            report(node, new RuleError(message));
        },
        [context.Syntax.Paragraph](node) {
            const message = localize(meta.messages["id-b"]);
            report(node, new RuleError(message));
        }
    };
};

Design

dependency flow:

rule.js explicitly depend on textlint.meta.json by design.
It allow to bundle a single file that include textlint.meta.json.
It is fit for browser.

meta file:

textlint.meta.json is separataed file.
It cab be written meta object for the rule.
Maybe, it is useful location for Options Schemas.
External application that include textlint can read textlint.meta.json without executing rule.js.

message format:
ICU formatter is better?

https://github.com/messageformat/messageformat depended on Intl.

And, Node.js does not support full-icu by default

Overlay:

Custom messages by textlint application user

application user can modify textlint.meta.json before to lint text by the rule.

Problem

This design is depended on location of textlint.meta.json.
Some rule use flat directory.

@azu
Copy link
Member Author

azu commented Jul 8, 2019

Option Schema is related

@azu
Copy link
Member Author

azu commented Jul 11, 2020

https://github.com/secretlint/secretlint/blob/master/docs/secretlint-rule.md
Secretlint implment messageId system.
It works and TypeSafe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

1 participant