Magento: Single Quotes in Translation Files Void Translation - magento
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"
Related
Converting a TXT file with double quotes to a pipe-delimited format using sed
I'm trying to convert TXT files into pipe-delimited text files. Let's say I have a file called sample.csv: aaa",bbb"ccc,"ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","nnn"ooo,ppp"qqq",rrr" sss,"ttt,""uuu",Z I'd like to convert this into an output that looks like this: aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z Now after tons of searching, I have come the closest using this sed command: sed -r 's/""/\v/g;s/("([^"]+)")?,/\2\|/g;s/"([^"]+)"$/\1/;s/\v/"/g' However, the output that I received was: aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|pppqqq|rrr" sss|ttt,"uuu|Z Where the expected for the 9th column should have been ppp"qqq" but the result removed the double quotes and what I got was pppqqq. I have been playing around with this for a while, but to no avail. Any help regarding this would be highly appreciated.
As suggested in comments sed or any other Unix tool is not recommended for this kind of complex CSV string. It is much better to use a dedicated CSV parser like this in PHP: $s = 'aaa",bbb"ccc,"ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","nnn"ooo,ppp"qqq",rrr" sss,"ttt,""uuu",Z'; echo implode('|', str_getcsv($s)); aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|nnnooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z
The problem with sample.csv is that it mixes non-quoted fields (containing quotes) with fully quoted fields (that should be treated as such). You can't have both at the same time. Either all fields are (treated as) unquoted and quotes are preserved, or all fields containing a quote (or separator) are fully quoted and the quotes inside are escaped with another quote. So, sample.csv should become: "aaa""","bbb""ccc","ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","""nnn""ooo","ppp""qqq""","rrr"" sss","ttt,""uuu",Z to give you the desired result (using a csv parser): aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z
Have the same problem. I found right result with https://www.papaparse.com/demo Here is a FOSS on github. So maybe you can check how it works. With the source of [ "aaa""","bbb""ccc","ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","""nnn""ooo","ppp""qqq""","rrr"" sss","ttt,""uuu",Z ] The result appears in the browser console: [1]: https://i.stack.imgur.com/OB5OM.png
Why doesn't 'text{$variable}' work for me?
I'm using the latest stable version of Smarty and can't get this string to work. I've looked at other questions for solution to do this but none seem to work. This is a template file (TPL), and doesn't contain any PHP at all. Note that the TPL file is compiled to a PHP script and then sent to the browser. It's not a PHP file. Current code: 'foo{$bar}' which outputs as: 'foo{$bar}' instead of the value of $bar. What am I doing wrong?
If you use any variables within text you have to use double-quotes " instead of single quotation marks '. Text within single quotation marks is not parsed for variables in PHP.
Absolute path in perl's copy command gone wrong?
This is my very simple code, which isn't working, for some reason I can't figure out. #!/usr/bin/perl use File::Copy; $old = "car_lexusisf_gray_30inclination_000azimuth.png"; $new = "C:\Users\Lenovo\Documents\mycomp\simulation\cars\zzzorganizedbyviews\00inclination_000azimuth\lexuscopy.png"; copy ($old, $new) or die "File cannot be copied."; I get the error that the file can't be copied. I know there's nothing wrong with the copy command because if I set the value of $new to something simple without a path, it works. But what is wrong in the representation of the path as I've written it above? If I copy and past it into the address bar of windows explorer, it reaches that folder fine.
Tip: print out the paths before you perform the copy. You'll see this: C:SERSenovodocumentsmycompsimulationrszzzorganizedbyviewsinclination_000azimuthexuscopy.png Not what we wanted. The backslash is an escape character in Perl, which needs to be escaped itself. If the backslash sequence does not form a valid escape, then it's silently ignored. With escaped backslashes, your string would look like: "C:\\Users\\Lenovo\\Documents\\mycomp\\simulation\\cars\\zzzorganizedbyviews\\00inclination_000azimuth\\lexuscopy.png"; or just use forward slashes instead – in most cases, Unix-style paths work fine on Windows too. Here is a list of escapes you accidentally used: \U uppercases the rest \L lowercases the rest \ca is a control character (ASCII 1, the start of heading) \00 is an octal character, here the NUL byte \l lowercases the next character.
If no interpolation is intended, use single quotes instead of double quotes.
Could bash use non printing character as quote?
This question originates from one use case, replace " with '', latex quirk. I usually use ' (single quote) to enclose the script if there is " (double quote) inside, and vise verse. However, in this case, both single quote and double quote appear in this script, and I had google to find the proper way to handle it. This one provides the solution. The following is the right, but not very readable solution. sed 's!"!'\'''\''!' {filename} After making it work, I began to think that this awkwardness comes from this quoting mechanics. Therefore, is it possible to use non printing character as the quote? Then, we don't need to escape quote any more.
In bash, you have single and double quotes, and here-docs and here-strings: You could do: sed_script=$(cat << 'END' s/"/''/g END ) sed "$sed_script" filename
Ruby - Making a newline within usage of gsub
I'm a bit stuck on this issue. I'm trying to make a newline using '\n'. I'm opening a file, then replacing the text, then writing it back as an html file: replace = text.gsub(/aaa/, 'aaa\nbbb') But this results in: aaa\nbbb I'm trying to make do: aaa bbb
In single-quoted strings a backslash is just a backslash (except if it precedes another backslash or a quote). Use double quotes: "aaa\nbbb" .
You'll want to read:Backslashes in Single quoted strings vs. Double quoted strings in Ruby?.