Prevent i18n from converting special characters to HTML - express

I want to translate a sentence with i18n within an express app using a google cloud function. Everything works despite that special characters are transformed into HTML special notation.
var STRING_TO_TRANSLATE = "{{name}} is here",
var translation = i18n.__(STRING_TO_TRANSLATE, {
name: "A & B"
});
This results in a translation "A & amp; B is here".
The expected result would be "A & B is here".
As I'm not using the translation in an HTML context, thus I need to get rid of the & amp. Any idea how to configure i18n to skip the HTML special character handling?

Related

Display UTF-8 JSPdf with VueJS

I am trying to display a catalog of products in pdf using JSPdf with VueJS. Data are coming from an API.
Base on the choice langage, the data will be in English, French etc...
Letters are working in English. But in French the problem is for letter like "é è à ç" etc... All this letter are displaying in a strange way. I read a lot of about setting a new font but it's still not working like this.
So I am coming here to see if somebody can share a script using VueJS to setup a custom fonts working with UTF-8 enconding.
Here is a minimal function but the idea is here:
download() {
let pdfRef = this.$refs.pdf;
html2canvas(pdfRef).then(canvas => {
let pdf = new jsPDF();
const str = "éçàeéi test";
pdf.save("Articles.pdf");
});
},
On the pdf i will see. Sometimes some letters are blank also.
é è à ç test
instead of
éçàeéi test
Thank you in advance.
Have a nice day!
Following this Link it's working perfectly. It's funny i following this doc before but i did not use a binary string to convert my ttf font.
I downloaded the font on google fonts and after i used a website to convert file ttf to base64 and get the string for the variable const myFont. Don't be scared because it can be thousand of letters
Just after the solution!
Thank you for your help and have a nice day :)
const myFont = ... // load the *.ttf font file as binary string
// add the font to jsPDF
doc.addFileToVFS("MyFont.ttf", myFont);
doc.addFont("MyFont.ttf", "MyFont", "normal");
doc.setFont("MyFont"); ```

Escape double quote in velocity

I'm using velocity 1.7 and the template is below.
var jsCode = "${code}";
eval(jsCode);
if code is "var id = 123", then the actual js code is
var jsCode = "var id = 123";
eval(jsCode);
there is no problem.
However, if the code is "var name = "lucy"", then the actual js code is
var jsCode = "var name = "lucy"";
eval(jsCode);
obviously there is syntax error.
And if the code is var jsonStr = "{\"id\":1, \"name\":\"lucy\"}", the the problem is more serious.
The code is unknown, it can be anything.
How to solve this problem?
Velocity developed also EscapeTool inside velocity-tools project which escape with different options
Tool for working with escaping in Velocity templates. It provides methods to escape outputs for Velocity, Java, JavaScript, HTML, HTTP, XML and SQL
In your case it's javascript so use $esc.javascript( example:
$javascript -> He didn't say, "Stop!"
$esc.javascript($javascript) -> He didn\'t say, \"Stop!\"

HTML string to PDF conversion

I need to create various reports in PDF format and email it to specific person. I managed to load HTML template into string and am replacing certain "custom markers" with real data. At the end I have a fulle viewable HTML file. This file must now be printed into PDF format which I am able todo after following this link : https://www.appcoda.com/pdf-generation-ios/. My problem is that I do not understand how to determine the number of pages from the HTML file as the pdf renderer requires creating page-by-page.
I know this is an old thread, I would like to leave this answer here. I also used the same tutorial you've mention and here's what I did to make multiple pages. Just modify the drawPDFUsingPrintPageRenderer method like this:
func drawPDFUsingPrintPageRenderer(printPageRenderer: UIPrintPageRenderer) -> NSData! {
let data = NSMutableData()
UIGraphicsBeginPDFContextToData(data, CGRect.zero, nil)
printPageRenderer.prepare(forDrawingPages: NSMakeRange(0, printPageRenderer.numberOfPages))
let bounds = UIGraphicsGetPDFContextBounds()
for i in 0...(printPageRenderer.numberOfPages - 1) {
UIGraphicsBeginPDFPage()
printPageRenderer.drawPage(at: i, in: bounds)
}
UIGraphicsEndPDFContext()
return data
}
In your custom PrintPageRenderer you can access the numberOfPages to have the total count of the pages

i18next json dot in key or label

JS: i18n.t("SOME TEXT TO BE TRANSLATED.")
JSON: "SOME TEXT TO BE TRANSLATED.": "Een stukje tekst om te vertalen"
i18n.t("SOME TEXT TO BE TRANSLATED.") gives me "SOME TEXT TO BE TRANSLATED.".
If I remove the "." (dot) from the label and the function t, than the text is translated.
How to solve this?
Documentation explains that dot is by default treated as a key separator. You can
replace dot with .
put dot outside translated string i18n.t("SOME TEXT TO BE TRANSLATED") + "."
change key separator
You can change namespace and/or key separator by setting options on init:
nsSeparator: ':::'
keySeparator: '::'
You can set "keySeparator" : false in your init option.
You could try using https://github.com/cheton/i18next-text. It allows you using i18next translation without having the key as strings, and you do not need to worry about i18n key naming. Furthermore, you can also register the i18n helper with Handlebars.
Following is a simple example:
var i18n = require('i18next');
// extends i18n object to provide a new _() method
i18n._ = require('i18next-text')._;
i18n._('Save your time and work more efficiently.');
Check out the demo on JSFiddle.

Customize the Prompt Box of Javascript

As the Title says, I am invoking a Prompt-box of very-flexible Javascript by the below command in my Silverlight application.
string input = System.Windows.Browser.HtmlPage.Window.Invoke("prompt", new string[] { "YOUR QUESTION GOES HERE", "THE ANSWER INPUT GOES HERE.." }) as string;
But what i want is to customize the prompt box in terms of resizing, alignment, and Prompt-box header content. How can i pass such parameters in the above code, without breaking its core Functionality ??
Jquery Plugins are available....you can use
http://theinfiniteloopblog.com/programming/jscript/custom-javascript-alert-and-confirm-dialog-boxes/