Giter VIP home page Giter VIP logo

arb-editor's Introduction

arb-editor

An extension to help you in editing .arb files, used for localization of applications.

Features

  • JSON schema for .arb validation.
  • Snippets for string, stringWithArgs, plural, and select messages.
  • Full support of ICU MessageFormat syntax.
  • Diagnostics and Quick fixes.

Sample .arb file

{
    "@@locale": "en",
    "@@x-template": "path/to/template.arb",
    "@@context": "HomePage",
    "helloAndWelcome": "Welcome {firstName} von {lastName}!",
    "@helloAndWelcome": {
        "description": "Initial welcome message",
        "placeholders": {
            "firstName": {
                "type": "String"
            },
            "lastName": {
                "type": "String"
            }
        }
    },
    "newMessages": "test {newMessages, plural, =0{No new messages} =1 {One new message} two{Two new Messages} other {test {newMessages} new messages}}",
    "@newMessages": {
        "type": "text",
        "description": "Number of new messages in inbox.",
        "placeholders": {
            "newMessages": {
                "type": "int"
            }
        }
    }
}

Customize

Escaping quotes can be turned off by including a l10n.yaml file with the line:

use-escaping: false

To set a template file, either set the @@x-template element in your arb file

"@@x-template": "path/to/template.arb"

or set a file to be the template in the l10n.yaml using:

template-arb-file: path/to/template.arb

arb-editor's People

Contributors

mosuem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

arb-editor's Issues

Extension causes high cpu load

  • Issue Type: Performance
  • Extension Name: arb-editor
  • Extension Version: 0.0.8
  • OS Version: Linux x64 5.17.5-76051705-generic
  • VS Code version: 1.79.0

The extension becomes unresponsive went I add a placeholder with plural or select in an arb file and completely freeze till i close and reopen the vs code window.

Google.arb-editor-unresponsive.cpuprofile.txt

Create new arb file

There should be an option to:

  1. Create a new blank arb file, with some basic structure which only needs to be filled in;
  2. Create an arb based on an existing file, choosing a locale, and copying all keys with empty messages to allow translators to add a new translation.

Ignore placeholder warning if template-arb-file is set

Expected Behavior

I would like to request the addition of a feature that allows developers to ignore 'specific linter rules' during arb analysis like "placeholder".

Actual Behavior

Currently, there is no way to ignore rules like 'Placeholder X not defined in the message metadata'. My 'template-arb-file' is set to my EN file and I should not need to duplicate my placeholder.

Specifications

  • Version of the linter or code analysis tool: v0.0.11
  • Platform: macOS

Add a CI for this repo?

We should likely have a CI for this repo (linting the typescript code, running tests, ...).

Escaping syntax not working

Expected Behavior

Escaping syntax as described in the docs should be supported.

  • Verbatim contexts within ' should not give error.
  • ' character, represented as '' within a verbatim context should be allowed.

Steps to Reproduce the Problem

{
  "helloWorld": "Hello! '{Isn''t}' this a wonderful day?"
}

Gives: Error: Unbalanced right delimiter found in string

Or:

{
  "helloWorld": "Hello!' {Isn''t}' this a wonderful day?"
}

Gives "{Isn''t}" is not a valid placeholder name.

Deflake tests

The Github action runs seem to be flaky, either failing or taking a long time. This should be investigated.

False error regarding missing template messages

Expected Behavior

When using a template and the message translation is present in the file, there should be no warnings that the message is not provided.

Actual Behavior

A warning is issued about a missing template.

Steps to Reproduce the Problem

  1. Create files below
  2. Observe the error

en.arb

{
    "@@locale": "en",
    "hello": "Hello",
    "@hello": {
        "description": "Say hello"
    }
}

en_UK.arb

{
    "@@locale": "en_UK",
    "@@x-template": "en.arb",
    "hello": "Hello"
}

There is a warning at en_UK.arb that translation for hello isn't provided even though it is.

Specifications

  • Version: 0.0.12
  • Platform: macOS, 14.3.1

Add quickfixes for errors

Some errors might have quick-fixes associated to them, for example if a placeholder is not declared in the metadata. It would be nice to include such quick-fixes.

Some minor feedback

@mosuem I had a quick scan through the code and had some feedback:

  1. Snippets are defined against the JSON language, so they show up for all JSON files (inc. non-ARB).
    I don't think there's an easy way to define a new language (ARB) in VS Code and have it inherit the functionality from another language. It would be nice to define "ARB" but inherit everything from "JSON" and then use ARB to target snippets etc., however you can supply snippets via a completion provider which would allow you to check the file extension before providing them. I did something similar in Dart-Code so we could conditionally include Flutter snippets only if the current project is a Flutter project (see Dart-Code/Dart-Code#350).
  2. I was a little surprised that the extension modified my user settings file (to add an association) without any prompt or action (I cam to add something and saw an unfamiliar entry at the end of the file). I think it could be done instead by using contributes/configurationDefaults in package.json to avoid modifying the settings (example of similar in Dart-Code).
  3. It probably doesn't matter too much for such a small extension, but currently in activationEvents is onStartupFinished which means the extension always activates. Generally it's better to only activate when it's certain the user needs the extension (for example onLanguage, or onCommand).. although, since we can't create an ARB language (without losing basic JSON support), onLanguage:json might be the best you can do.
  4. Repository/bugs field in package.json point to https://github.com/mosum/arb-editor (I presume these should be google, but if not, is the username still a typo?)
  5. I noticed in #1 you're using jsonc-parser.. Is the intention to support comments in these files? (I ask because VS Code has a separate "JSON with comments" language, but I'm not sure if it's safe to have comments here if other tools might be reading the files that might not accept them).
    FWIW, I noticed the visitor in that parser is already providing offsets which deals with one thing discussed earlier.

Commit `Fix quote escaping behavior` changed behaviour when `use-escaping: false` setting (default)

Recent commit #40 changes default behaviour of ARB string parser to no longer accept

"zzTestString":"Testing a string's apostrophe capability",

The above test string fail with Error: Unbalanced escape quotes. To escape a single quote ', prefix it with another single quote. however, adding a two-quote like "zzTestStringDouble":"Testing a string''s apostrophe capability", generates incorrect Dart string if a single-apostrophe is desired as flutters gen-l10n setting use-escape defaults to false. With a use-escape: false there now is no way to have arb-editor plugin accept the above zzTestString. The gen-l10n tool works fine and outputs correct single-apostrophe string for the zzTestString string.

To fix this, I have a few options:

  • Add use-escaping: true setting and two-quote everywhere in my ARB file
  • Switch all strings to begin with single-quote, then escape apostrophe where found.

Neither is ideal imho. I believe out-of-box should not mark this test string as erroneous.

Provide a way to ignore specific errors/warnings

Expected Behavior

Have a way for a user to define specific errors/warnings/infos that they want to ignore and not show in the Problems section of vscode. May be via a plugin setting to list IDs of the messages user wants to disable, for example:

{
...
"arbeditor.supressedWarnings": [3, 7] // Disable no metadata for key and placeholder metadata errors
}

Actual Behavior

There is no way for a user to ignore a specific warning that the plugin generates while it validates the ARB file. For example, not defining metadata for key/placeholder.

Specifications

  • Version: 0.0.12
  • Platform: macOS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.