question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support multiline from JSON

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request

Current behavior

{
  "multiline": [
     "Some long string that ",
     "would be prefered to be written over ",
     "multiple lines in JSON"
  ]
}

Shows up on screen with the commas , of the array in between.

Some long string that ,would be prefered to be written over ,multiple lines in JSON

Expected/desired behavior

String without commas from array.

What is the motivation / use case for changing the behavior? To be able to use multiple lines in case of maximum line-width for readability purposes.

Please tell us about your environment:

  • ng2-translate version: 3.1.3

  • Angular version: 2.1.1

  • Browser: Chrome 54

  • Language: TypeScript 2.0.6

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
Iv3li0scommented, Jan 26, 2018

Base on supertorpe comment. But no need to create another pipe ( which not include query translate params ) You can directly override TranslateParse.

export function createTranslateParser() {
  return new TranslateAppParser();
}

@NgModule({
  declarations: [
   ...
  ],
  imports: [
  ...
    // Translate
    HttpClientModule,
    TranslateModule.forRoot({
      parser: { provide: TranslateParser, useFactory: (createTranslateParser)}
    }),
...
import {Injectable} from '@angular/core';
import {TranslateDefaultParser} from '@ngx-translate/core';

@Injectable()
export class TranslateAppParser extends TranslateDefaultParser {

  getValue(target: any, key: string): any {
    target = super.getValue(target, key);
    if (target instanceof Array) {
      target = target.join(' ');
    }
    return target;
  }
}
1reaction
ocombecommented, Dec 1, 2016

yes, once I’ve chosen the new name / namespace, it will be easy to release new loaders like that 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are multi-line strings allowed in JSON? - Stack Overflow
JSON does not allow "real" newlines in its data; it can only have escaped newlines. See the answer from @YOU. According to the...
Read more >
JSON Multi-Line String - Linux Hint
JSON does not natively support multi-line strings. This can be quite frustrating when looking for flexibility and storing large texts.
Read more >
Storing multi-line strings in JSON with JSONLint - Gun.io
This quick hack helps find a way to store multi-line strings in JSON to interact with JS and Node.
Read more >
Working with JSON ( JSONL) & multiline JSON in Apache Spark
JSON ) on Spark 2.1 and I faced a very peculiar issue while working on Single Line JSON(aka. JSONL or JSON Lines )...
Read more >
Solved: multi line string in json is being rejected.
multi line string in json is being rejected · 1. Add a compose above the HTTP action step. · 2. Construct the query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found