Symfony 3.1 HTML in xlf translation file - translation

As recommended by Symfony I'm using xlf files for the translations.
I want to store a message which has a HTML tags, let's say:
Welcome back <a href='/user/profile'>user</a>.
I have discovered that you can't include this literal in the target section because you get an exception caused by the "<" and ">" chars.
I'm unable to find a way to escape this chars unless using the < and > .
Is there another solution?. Any suggestions?

Related

Carrierwave: Use spaces instead of underscore

We have an uploader for PDF's. When a file name has spaces in it, they are automatically being converted to use underscores:
some file test -> some_file_test
I'd like to keep the spaces. Can someone tell me how?
I tried:
def filename
original_filename
end
You can override sanitize regexp by adding whitespace:
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+\ ]/
As you see this regexp used in sanitize method that replace forbidden symbols to underscore.
From CarrierWave documentation:
Filenames and unicode chars
Another security issue you should care for is the file names (see Ruby On Rails Security Guide). By default, CarrierWave provides only English letters, arabic numerals and some symbols as white-listed characters in the file name. If you want to support local scripts (Cyrillic letters, letters with diacritics and so on), you have to override sanitize_regexp method. It should return regular expression which would match all non-allowed symbols.
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party plugins or client-side software.
Try:
original_filename.gsub("_", " ")
UPDATE (possible workaround):
Replace underscores with a character or a string (e.g. "xyxyxyxyxyxyxyxyz") you are not expecting in filenames before passing them to carrierwave i.e.
filename.gsub("_", "your_special_character/s")
Replace underscores with spaces and special character with underscores later:
original_filename.gsub("_", " ")
original_filename.gsub("your_special_character/s", "_")

—- " added in HTML when converting MarkDown file to HTML using Jekyll tool

I have used Jekyll tool to convert MarkDown file To HTML. It has been successfully converted to HTML. but the below following encoded punctuation characters has been added at the top of the HTML, due to the file encoded format is Encode in UTF-8.
"—-"
After changed the same markdown file to Encode in ANSI format in NotePad++[encoding option in menu bar]. The punctuation character not included in generated HTML.
In this we need to manually change the markdown file to ANSI for HTML generation 'Jekyll'.
Any solution for this?
 is the UTF-8 BOM so that's probably what you are seeing, assuming you are looking at it using CP1252; and — is something out of the General Punctuation block.
Proper diagnostics are not possible without an indication of which character encoding you are using instead of UTF-8 to view the file, and/or what exact bytes you have in the file, probably as a hex dump. The first few bytes (the BOM) would be EF BB BF. See also the character-encoding tag wiki for troubleshooting tips.
Quick googling indicates that Jekyll is highly allergic to UTF-8 BOM in its input, so it seems unlikely that it generates spurious BOM characters on output. I could speculate that the template file you are using has a BOM and that it is being faithfully included in the output, but I'm not really familiar enough with Jekyll to actually help troubleshoot any further.
Of course, as per the big ugly warnings all over the Jekyll site, I assume you have already made sure that your Markdown input doesn't have a BOM character. Many Windows editors are notorious for putting one in when you save as UTF-8; make sure you use "UTF-8 without a BOM" as the "Save As..." format -- and switch to an editor which offers this option if yours doesn't have it.
try using charset=utf-8
or
Check your content has any straight double quote (" ") or straight single quote (' ') and remove those
http://practicaltypography.com/straight-and-curly-quotes.html
This encoding format issue. make the markdown file in UTF-8 without BOM format.
This will remove the punctuation character in 'html' .

Rails: Is it a bad idea to put double-byte character inside a model?

I've learnt that you may define a Ruby source file as UTF-8 to be able to key inside it double-byte characters (e.g.: ¤) instead of their HTML code (e.g.: & curren;):
# encoding: UTF-8
class Price < ActiveRecord:Base
def currency_symbol
'¤'
end
end
Without the encoding statement, I would need to write '& curren;'.html_safe as the core of the method.
I don't like the later because it assume I'm writing HTML (I have Excel output in my app on top of HTML).
My question is: Is there any problems or performance hits I must be aware while doing this?
Note: Ruby 2.0 brings UTF-8 as the default encoding; does it mean all Ruby files will automatically support all those characters?
Character chart: http://dev.w3.org/html5/html-author/charref
This is exactly the kind of thing that should go in the locales (config/locales). These are YAML files that define words and characters that will be used in the various parts of your application, including currency symbols. It also has the benefit of allowing you to easily introduce translations for other languages.
Take a look at the ruby on rails guide for i18n for more.

Gettext throws "warning: unterminated string" when parsing twig template files

This problem has been bothering me for a while, but I would like to fix it once and for all.
I am using the twig template engine in my PHP application. I am using the latest version of Poedit (which uses xgettext 0.18.1) to parse my files for translation strings.
I have set up Poedit to work with twig using these instructions.
Everything works well, but the problem is that when I update my Poedit catalogue, I get errors like this:
1:24:45 PM: somefile.twig:5: warning: unterminated string
1:24:45 PM: somefile.twig:10: warning: unterminated string
This is the dialog:
And this is the file in question:
{% extends somevar ? 'one.twig' : 'two.twig' %}
{% block blah %}
Blah blah
{% endblock %}
{% block blah2%}
<div id="some-id" class="some-class">
some content
</div>
{% endblock %}
However, if I click OK in the error dialog, everything seems to be fine and the strings from the twig template are then loaded into the catalogue.
I know there is a gettext-extractor for twig that has been released recently to pick out the translation strings. However, there are some possible issues:
I am not using the symfony 2 framework and am not using the intl extension for twig (we have built our own to suit our purposes).
We use a different character for our gettext strings {{ t('some string') }}
We would prefer not to have to introduce more external dependencies unless we really have too, otherwise someone trying to get the strings would need to set up twig and the gettext extractor.
Is there a flag I can pass to xgettext to solve this problem? The parsing works fine. I just prefer that the error to not be thrown by gettext.
Change Setting like this:
Go to Prefernces -> Parsers
Select PHP -> Edit
List of Extentions .... -> .php,.phtml
Insert this "xgettext --language=PHP --force-po -o %o %C %K %F" into Parser Command: field.
And also Catalog --> Properties --> Translation Properties TAB --> Charset utf-8
So I continued using that workflow for a few days and found the following problem:
If I have a resource bundle key like so: Test, the settings I was using previously would not pick up the key.
Since I already had a small PHP script in the background to monitor and compile my assets using Assetic, I simply added a few more lines for the twig templates to be compiled into PHP files (http://twig.sensiolabs.org/doc/extensions/i18n.html#extracting-template-strings).
I then remove the Twig parser from POEdit and now, all the template strings are just parsed from PHP files, which works great!
While this solution works, I would still like to find a way to get POEdit and gettext to parse twig files natively. However, if anyone is looking for a solution, this one should work quite well in the meantime.

How to disable RSpec2 UTF-8 and HTML characters escaping?

WIth ruby 1.8.7 and rails 3.0.3 on Mac OS I always got "&#...;" characters in ERB template output running rspec 2.4 controllers tests (with integrate_views).
Besides "&" character and Cyrillic characters are always escaped, even using <%= raw '...' or html_safe methods.
Can anybody give a clue - what's going on here?
You mean console/terminal output?
Try editing you ~/.profile file and pasting this line:
export LANG=sr_YU.UTF-8
You can find listing of all available locales here.
Replace sr_YU with your own cyrillic locale.

Resources