react-native-thermal-printer icon indicating copy to clipboard operation
react-native-thermal-printer copied to clipboard

Support for language other than english say for example arabic

Open Roshankurikkal opened this issue 3 years ago • 12 comments

Printing text in language other than english

Roshankurikkal avatar Jun 28 '22 06:06 Roshankurikkal

Have you tried TTS?

Derrickkoko1234 avatar Jun 28 '22 06:06 Derrickkoko1234

Have you tried TTS?

I havent. Would you guide me on how to do this . I am fairly new to this react native thing Is there a way to change the charset encoding to utf-8 ? That might to do it

Roshankurikkal avatar Jun 28 '22 06:06 Roshankurikkal

https://www.npmjs.com/package/react-native-tts

I am still in the dark here , how would a text to speech helps me in printing arabic on a thermal printer ?

Roshankurikkal avatar Jun 28 '22 06:06 Roshankurikkal

Sorry. I meant google translate https://www.npmjs.com/package/google-translate-open-api

Derrickkoko1234 avatar Jun 28 '22 06:06 Derrickkoko1234

Example:

import translate from 'google-translate-open-api';
const result = await translate(`I'm fine.`, {
  tld: "cn",
  to: "zh-CN",
});
const data = result.data[0];
 
// 我很好。

or

import translate, { parseMultiple } from 'google-translate-open-api';
 
const result = await translate([`I'm fine. And you?`,`I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
});
// [[[[["<i>I&#39;m fine.</i> <b>我很好。</b> <i>And you?</i> <b>你呢?</b>"]],null,"en"],[[["我可以。"]],null,"en"]]]
 
// use parseMultiple
const data = result.data[0];
const parseData = parseMultiple(data);
// ["我很好。你呢?","我可以。"]

Derrickkoko1234 avatar Jun 28 '22 06:06 Derrickkoko1234

Example:

import translate from 'google-translate-open-api';
const result = await translate(`I'm fine.`, {
  tld: "cn",
  to: "zh-CN",
});
const data = result.data[0];
 
// 我很好。

or

import translate, { parseMultiple } from 'google-translate-open-api';
 
const result = await translate([`I'm fine. And you?`,`I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
});
// [[[[["<i>I&#39;m fine.</i> <b>我很好。</b> <i>And you?</i> <b>你呢?</b>"]],null,"en"],[[["我可以。"]],null,"en"]]]
 
// use parseMultiple
const data = result.data[0];
const parseData = parseMultiple(data);
// ["我很好。你呢?","我可以。"]

i went through this but here is what i want to print

const text = '[C]' + ${print?.base_url}${print?.companyDetails?.CompanyLogo} + '\n' + '[L]\n' + "[C]" + print?.companyDetails?.CompanyName_Lang + "\n" + "[C]" + print?.companyDetails?.CompanyName + "\n" + "[C]" + address + "\n" + '[L]\n' + '[L]\n' + '[C]فاتورة ضريبیة مبسطة\n' + '[C]VAT No :' + customer?.VATNo + '\n' + '[L]\n' ;

i want to print this in line 6 but it returns an empty line . would this be possible with the above mentioned library

Roshankurikkal avatar Jun 28 '22 06:06 Roshankurikkal

You can create a function that converts text to your language and returns the converted text.

Then anywhere you want to convert print text, you call the function

Derrickkoko1234 avatar Jun 28 '22 06:06 Derrickkoko1234

You can create a function that converts text to your language and returns the converted text.

Then anywhere you want to convert print text, you call the function

i am sorry if iam in the wrong here but i have the arabic text and i would like to print it exactly like that without converting to any other langauage

'[C]فاتورة ضريبیة مبسطة\n'

this return an empty line

Roshankurikkal avatar Jun 28 '22 06:06 Roshankurikkal

Then don't call the function on the line...

Derrickkoko1234 avatar Jun 28 '22 07:06 Derrickkoko1234

@Derrickkoko1234 he is asking about char encoding As this package doesn't support Arabic encoding.

Mohamed-kassim avatar Jul 10 '22 13:07 Mohamed-kassim

any update ? @Mohamed-kassim @Roshankurikkal

yaser-elbatal avatar Dec 20 '23 11:12 yaser-elbatal

any update ? @Mohamed-kassim @Roshankurikkal

I ended up capturing what i need to print as png using react native viewshot and printing that as an image using jansulo/react native bluetooth thermal printer

roshancaxigo avatar Dec 21 '23 03:12 roshancaxigo