Ticket #569 (closed enhancement: fixed)

Opened 3 months ago

Last modified 2 months ago

jLocale : support multiline rendering in strings

Reported by: Julien Assigned to: Julien
Priority: low Milestone: Jelix 1.1 beta 1
Component: jelix:core:jLocale Version: 1.0.3
Severity: minor Keywords:
Cc: Php version:
Review: review+ Hosting Provider:
Documentation needed: 0 Blocking:

Description

Sometimes, when we have to translate quite long texts, we may need line breaks in it.

Right now, we cannot insert \n in strings, because it won't be treated as a line break.

We already have the ability to write strings on multiple lines in the properties files, like this

mystring = This a string that will be returned\
on one line, even if it's declared on 2 lines in the property file

but the string is still returned in 1 single line.

I propose the following syntax (\\ at end of line) to get the string returned with a line break :

mystring = This a string that will be returned\\
with a line break

The jlocale html plugin will also be updated to render <br /> at line breaks.

Attachments

569-jLocale-support-multiline-rendering-in-strings.diff (1.5 kB) - added by Julien on 05/04/08 19:33:09.
patch for handling \n in strings and getting <br /> tags with html jlocale plugin for jtpl
569-jLocale-support-multiline-rendering-in-strings.2.diff (4.0 kB) - added by Julien on 05/05/08 20:08:39.
improved patch and unit test
569-jLocale-support-multiline-rendering-in-strings.3.diff (5.1 kB) - added by Julien on 05/28/08 11:12:18.
fixed patch for multiline strings in properties files

Change History

05/01/08 10:45:21 changed by Julien

  • status changed from new to assigned.

05/01/08 18:04:00 changed by laurentj

I don't like this syntax. I prefer a support of classical escaped characters like \n, \r, \t etc..

05/04/08 19:17:46 changed by Julien

Ok for that syntax.

I think supporting \n is enough about this ticket's description, no ?

The patch would basically do something like :

$str = str_replace('\n',"\n",$str);

and the jlocale html plugin will use nl2br() PHP function to get a <br /> tag.

05/04/08 19:33:09 changed by Julien

  • attachment 569-jLocale-support-multiline-rendering-in-strings.diff added.

patch for handling \n in strings and getting <br /> tags with html jlocale plugin for jtpl

05/04/08 19:36:15 changed by Julien

  • review set to review?.

(follow-up: ↓ 6 ) 05/04/08 23:45:03 changed by laurentj

  • priority changed from normal to low.
  • review changed from review? to review-.
  • severity changed from normal to minor.
  • milestone set to Jelix 1.1 beta 1.

The replacement of '\n' by "\n" should be done during the load of the ressource file, so it doesn't need to do this replacement each time we want to get the string.

I would like also a unit test on this new feature.

(in reply to: ↑ 5 ) 05/05/08 13:15:14 changed by Julien

Replying to laurentj:

The replacement of '\n' by "\n" should be done during the load of the ressource file, so it doesn't need to do this replacement each time we want to get the string.

Ok for that, no problem

I would like also a unit test on this new feature.

Ok, so I'll write a test for testing '\n' to "\n" conversion.

05/05/08 20:08:39 changed by Julien

  • attachment 569-jLocale-support-multiline-rendering-in-strings.2.diff added.

improved patch and unit test

05/05/08 20:11:37 changed by Julien

  • review changed from review- to review?.

Here's the new patch. I also added a unit test, but I'm not really sure I did what you wanted to (I'm a beginner with unit tests). Don't hesitate to correct me if I'm wrong.

05/28/08 10:18:21 changed by laurentj

  • review changed from review? to review-.

The replacement should be done at two lines: 123 and 133, not at line 141.

  str_replace(array('\#','\n'),array('#',"\n") ....);

So add a test with a multi-line string ;-)

05/28/08 11:12:18 changed by Julien

  • attachment 569-jLocale-support-multiline-rendering-in-strings.3.diff added.

fixed patch for multiline strings in properties files

05/28/08 11:13:59 changed by Julien

  • review changed from review- to review?.

Thanks for the report, I actually missed that line :(

So here's the new patch, with a new unit-test.

05/28/08 11:28:09 changed by laurentj

  • review changed from review? to review+.

patch is ok, thanks :-)

05/28/08 13:50:09 changed by Julien

  • status changed from assigned to closed.
  • resolution set to fixed.

commited

05/28/08 14:32:58 changed by laurentj

not in 1.0.x branch !

05/28/08 14:33:52 changed by laurentj

remove your patch from 1.0.x branch please

05/28/08 15:14:29 changed by Julien

removed the patch in 1.0.x

sorry for that :(

Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed