Escape double quotes inside single quoted text - spring-boot

With spring boot 3.0.1 and thymeleaf 3.1 in the below expression:
<a th:replace="~{fragments/paging :: paging(${totalPages}, ' Last >>', 'Last Page')}"></a>
I am trying to replace ' Last >>' with ' <i class="fa-solid fa-forward-step"></i>' and hence need to escape double-quotes.
I tried the suggestions and solutions suggested here, here and other SO threads but none of them seem working.
When I try using " the text appears as it while for other options I get parsing error. What I am missing? After trying so many options I am feeling clueless. Any suggestion will be helpful.

Related

Spring Batch EL expression - can't escape # sign

I am using Spring Batch 2.1.9 and have a requirement to write a file name with some text and the run date delimited by a # sign. Unfortunately I can't find a way to display a # sign without breaking the expression. I have tried the following formats, all to no avail:
File##{jobParameters[rundate]}
File#{'#' + jobParameters[rundate]}
File${'#'}#{jobParameters[rundate]}
File#{'#'}#{jobParameters[rundate]}
Anytime that extra pound sign is included, the rest of the expression fails to display anything. Is there an obscure way to escape a pound sign?
Have you tried to use String.format("%s#%s",file,rundate) as SPEL?

Ruby regex and special characters like dash (—) and »

I'm trying to replace all punctuation and the likes in some text with just a space. So I have the line
text = "—Bonne chance Harry murmura t il »"
How can I remove the dash and the dash and »? I tried
text.gsub( /»|—/, ' ')
which gives an error, not surprisingly. I'm new to ruby and just trying to get a hang of things by writing a script to pull all the words out of a chapter of a book. I figure I'd just remove the punctuation and symbols and just use text.split. Any help would be appreciated. I couldn't find much
It turns out the problem had to do with the utf-8 encoding. Adding
# encoding: utf-8
solved my issues and what #Andrewlton said works great
This should properly substitute in the way you were trying to do it; just add brackets and remove the pipe:
text.gsub(/[»—]/, ' ')
The standard punctuation regexp also works:
text.gsub(/\p{P}/, ' ')
You should be able to use regexp pretty universally, coming from whatever language you know. Hope this helps!

preg_match warning

I have deprecated "eregi" problem.
if (eregi("data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)", $edit_img, $tmp))
So I changed into this,
if (preg_match("/data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)/i", $edit_img,$tmp))
But I got new warmingmessage,
Warning: preg_match() [function.preg-match]: Unknown modifier 'c'
Please let me know what is wrong.
Thanks in advance.
You have a '/' inside your regex ('data/cheditor') but you are also using '/' as the regex delimiter ('/myregex/flags'): you can either escape the internal '/', or use a different regex delimiter.
E.g. first option:
preg_match('/data\/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)/i',...
or (second option, I chose '#' as the delimiter):
preg_match('#data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)#i',...
Also note I changed the " around your regex to ' because otherwise you need to double the backslashes within double-quotes in PHP.

Magento: Single Quotes in Translation Files Void Translation

I am trying to translate some strings from a Magento 1.5.x install and it works fine when there is a double quote, but I cannot properly escape single quotes.
"Hello, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>","Hello, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>","Olá, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>"
"<button class=""form-button"" onclick=""setLocation(\'%s\')"" type=""button""><span>Login or Register</span></button>","<button class=""form-button"" onclick=""setLocation(\'%s\')"" type=""button""><span>Login ou Cadastro</span></button>"
I've tried the original string as is, and escaped with a backslash. I've tried the translated string escaped with a backslash and double single quotes.
I tried searching the magento forum, but the only two people that posted about this problem got no replies.
When you escape a single-quote with a backslash in the .phtml file, you need to remove the backslash from the translation string in the .csv file.
Example:
<?php echo $this->__('Click here to print a copy of your order confirmation.', $this->getPrintUrl())
Should be in .csv file:
"Click here to print a copy of your order confirmation.", "Click here to print a copy of your order confirmation."
without the backslashes, otherwise the string won't get translated. As usual double-quotes in the .csv have to be escaped with another double-quotes.
Some .csv translation files in Magento 1.7.0.2 still have these backslashes before single-quotes, which is a minor bug that needs to be fixed.
Try this
Other option is that you can put error message in double quotes as
__("Please specify the product's option(s).");
and in translation file you make it by simple this
Colum ONE | Colum Two
Please specify the product's option(s). | TRANSLATION OF that FILE
remove \ from Translation file and from code make it DOUBLE QUOTES in stead of single quote.
It turns out that the way the strings were being output in PHP were not compatible with Magento's translation engine. The fix comprised changes in the PHP file, not in the syntax of the translation files. The PHP files now read:
echo $this->__('Hello') . ', <strong>'.Mage::getSingleton('customer/session')->getCustomer()->getName().'!</strong>';
echo ('<button class="form-button" onclick="setLocation(\'' . $this->getUrl('customer/account/login') . '\')" type="button"><span>') . $this->__('Login or Register') . '</span></button>';
as opposed to having everything inside one echo $this->__('String to be translated . phpcode. String to be translated . phpcode . etc . etc')
You should never put html in a translated string. Magento uses vsprintf (http://php.net/manual/en/function.vsprintf.php) so it's easy to add a variable to a translation like this:
echo '<strong>'.$this->__('Hello %s!',Mage::getSingleton('customer/session')->getCustomer()->getName()).'</strong>';
In this way you can then translate easily in a csv: "Hello %s","Hola %s"

in Ruby, trying to convert those weird quotes into "regular" quotes

I am trying to parse a text file that has the weird quotes like
“ and ” into "normal quotes like "
I tried this:
text.gsub!("“",'"')
text.gsub!("”",'"')
but when it's done, they are still there and show up as
\x93 and \x94
so I tried adding that too with no luck:
text.gsub!('\\x93', '"')
text.gsub!('\\x94', '"')
The problem is, when I try to show those weird quotes on a webpage, it makes that weird diamond with a question mark symbol: �
It seems to work:
text = "“foo”"
=> "\342\200\234foo\342\200\235"
irb(main):002:0> text.gsub!("“",'"')
=> "\"foo\342\200\235"
irb(main):003:0> text.gsub!("”",'"')
=> "\"foo\""
You need to use a hex editor to figure out all the character codes involved.
Re: the second question of why the weird quotes show on a web page as the � symbol:
Your problem is that your web page is not in UTF-8 mode. To get it there, see
http://www.w3.org/International/O-HTTP-charset
If you can't change your web server, add a meta line in the head section of your web pages: http://www.utf-8.com/
Larry
Your first gsubs should work. The reason the second set of gsubs don't work is that you're using single quotes and double backslash. Try the other way around:
text.gsub!("\x93", '"')
text.gsub!("\x94", '"')
You can also do this in one line:
text.gsub!("\x93", '"').gsub!("\x94", '"')
# or
text.gsub!(/(\x93|\x94)/, '"')
Are you sure the encoding of the string is correct?

Resources