1

I'm translating an ugly formatted lang file of a plugin. It's really uncomfortable as it has no line breaks at all.

How do I enter \n after } and most of all after "text":"text",

Example of what the code looks like:

{"dir":"ltr","editor":"Rich Text Editor","common":{".........

I'm new to regex and find it difficult to learn these operators :D

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Ventricle
  • 65
  • 5

4 Answers4

5

To me this looks like JSON. If this is the case, simply:

  1. Install the JSTool plugin.
  2. Paste your string/open the file containing your string.
  3. Go to Plugins -> JSTool -> JSFormat.

Given this string:

{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}

It yields:

{
    "glossary" : {
        "title" : "example glossary",
        "GlossDiv" : {
            "title" : "S",
            "GlossList" : {
                "GlossEntry" : {
                    "ID" : "SGML",
                    "SortAs" : "SGML",
                    "GlossTerm" : "Standard Generalized Markup Language",
                    "Acronym" : "SGML",
                    "Abbrev" : "ISO 8879:1986",
                    "GlossDef" : {
                        "para" : "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso" : ["GML", "XML"]
                    },
                    "GlossSee" : "markup"
                }
            }
        }
    }
}

This approach should provide you with a decent indentation as well, which should help you better make sense of what you have. Although replacing with a regular expression will work, the output could be slightly messy.

npinti
  • 51,780
  • 5
  • 72
  • 96
  • Oh man thanks! That's it :) Better than replacing with regex :D After I'm done translating, should I deformat it? I've heard that affects performance of the script. – Ventricle May 26 '15 at 16:35
  • @Vioner: I am not sure on this, however, having the string in a single line *usually* reduces the size of the file, which when transmitting things tends to be a good thing. It is up to you really. – npinti May 27 '15 at 06:32
1

You do not need a regular expression here, just use the Extended mode:

Find what: }

Replace with: }\n

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0
  • Find What : }
  • Replace with: }\n

Should work after enabling Regular expression.

Whitebird
  • 185
  • 2
  • 13
0

Find } and replace it to }\n.
and you wanted to check "text":"text",
so find "," and replace to ",\n" will work for you.

MineSky
  • 97
  • 1
  • 11