flutterlocalizationcommentsflutter-easy-localization

How to add comments line in flutter easy localization translation file?


I could not figure it out how to add comments line in the translation file of easy localization package for flutter. The file is in Json format. This can be useful in large file.


Solution

  • Can I add a comment in JSON? No, JSON is a data-only format. Comments in the form //, #, or /* */, which are used in popular programming languages, are not allowed in JSON. You can add comments to JSON as custom JSON elements that will hold your comments, but these elements will still be data.

    way1.

    JSONC Example with JavaScript-style Comments
    { /*
       This is a multi-line
       comment in a JSONC.
       */
    
       "Id":1 // This is a single-line comment in JSONC.
    }
    

    way2.

    Multiple JSON Comments Example
    {
      "Id": 1,
      "//first_comment":  "The first JSON comment.",
      "//second_comment": "The second JSON comment."
    }