Can I use newlines in translations?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
AbaddonOrmuz
Registered User
Posts: 601
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Can I use newlines in translations?

Post by AbaddonOrmuz » Sat Mar 23, 2019 8:12 pm

Are newlines allowed in translation files?

I'm developing a syntax highlighter extension with line numbers for my Markdown extension, and in the help page I'm showing code inside <pre><code>...</code></pre>

As you may know, line breaks (<br>) does not count as a newline:

Code: Select all

'HELP_MARKDOWN_CODE_ANSWER' => '<pre class="markdown-demo"><code class="language-markdown">```ruby<br />puts "Hello #{user}!"<br />```</code></pre>';
Image

The following generates the output I want:

Code: Select all

'HELP_MARKDOWN_CODE_ANSWER' => '<pre class="markdown-demo"><code class="language-markdown">```ruby'.PHP_EOL.'puts "Hello #{user}!"'.PHP_EOL.'```</code></pre>'
Image

The keys are passed as is using the help manager (@phpbb.help.manager) so I don't think I can manipulate those string once they're added.

Code: Select all

		$this->manager->add_block(
			'HELP_MARKDOWN_BLOCK_CODE',
			false,
			[
				'HELP_MARKDOWN_QUOTE_QUESTION' => 'HELP_MARKDOWN_QUOTE_ANSWER',
				'HELP_MARKDOWN_CODE_QUESTION' => 'HELP_MARKDOWN_CODE_ANSWER',
				'HELP_MARKDOWN_CODE_INLINE_QUESTION' => 'HELP_MARKDOWN_CODE_INLINE_ANSWER'
			]
		);
So after all this explanation, can I use PHP_EOL in translation files? Would it pass validation?
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
3Di
Former Team Member
Posts: 13664
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Can I use newlines in translations?

Post by 3Di » Sat Mar 23, 2019 11:44 pm

Tried with <p>?
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
AbaddonOrmuz
Registered User
Posts: 601
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Can I use newlines in translations?

Post by AbaddonOrmuz » Sun Mar 24, 2019 2:28 am

Ye, the problem is that HTML line breaks (<br>) and paragraphs (<p>) are treated differently than newline characters (\n) by <pre>.
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
david63
Registered User
Posts: 16063
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Can I use newlines in translations?

Post by david63 » Sun Mar 24, 2019 8:35 am

I am sure you have done your research on this but have you read this - https://stackoverflow.com/questions/128 ... nt-php-eol where it seems to imply that there could be issues with servers/browsers, particularly Windows servers.

The recommendation on there is that you use \n - have you tried that?

(As a side note you should have a space either side the . to conform to the coding guidelines)
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
AbaddonOrmuz
Registered User
Posts: 601
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Can I use newlines in translations?

Post by AbaddonOrmuz » Sun Mar 24, 2019 5:10 pm

Yes, I've tried with \n, I would need to use double quotes though, but I was wondering if that's allowed.

But in fact, is the other way arround, PHP_EOL should be used instead, as it will choose the right newline character depending on the OS the script is running on.

So I guess it would pass validation if I use PHP_EOL?
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
david63
Registered User
Posts: 16063
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Can I use newlines in translations?

Post by david63 » Sun Mar 24, 2019 5:35 pm

AbaddonOrmuz wrote:
Sun Mar 24, 2019 5:10 pm
t will choose the right newline character depending on the OS the script is running on.
But the way I read it is that it is not always compatible with the browser OS
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
AbaddonOrmuz
Registered User
Posts: 601
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Can I use newlines in translations?

Post by AbaddonOrmuz » Sun Mar 24, 2019 8:40 pm

The OS of the client shoudn't matter as the script will be handled by the server, not the browser, besides phpBB itself uses PHP_EOL.

I'll use that, I hope when I submit my extension for validation, it won't be rejected.
A proudly user of Arch Linux :: /r/sddm_themes

Post Reply

Return to “Extension Writers Discussion”