Cucumber, Rspec: unicode symbols in output - unicode

I wonder if it is possible to make Cucumber output matching errors in Russian instead of this:
Сценарий: Успешное добавление кгиги # features/books/add_book.feature:12
Если я добавил книгу # features/step_definitions/books_steps.rb:3
То я должен увидеть добавленную книгу # features/step_definitions/books_steps.rb:15
expected there to be content "\320\235\320\260\320\267\320\262\320\260\320\275
\320\270\320\265 \320\272\320\275\320\270\320\263\320\270" in "\320\236\321\210\320\270\320
\261\320\272\320\260 502!\n...
Where "\320\235\320\260\320\267\320\262\320\260\320\275" is a Russian word. It may be a feature of Rspec. Any Ideas would be great.

Adding
$KCODE='u'
to my features/support/env.rb helped a little:
А должен увидеть сообщение о том, что пароль неверен
expected there to be content "Неверный прол\321\214"
This solution is only for 1.8.7 – in 1.9.3
# encoding: utf-8
works just fine

Related

html2pdf not showing character correctly, encoding for ē

I'm struggling with some characters in a PDF I'm trying to create with html2pdf. The following code creates the PDF, but ē is shown an e.
$html2pdf=new Html2Pdf();
$html2pdf->writeHTML('<h1>Fēnix</h1>');
$html2pdf->output();
When getting the name from my database, ē is shown a ?.
$query=$mysqli->query('SELECT name FROM table WHERE id=1;');
$result=$query->fetch_assoc();
$html2pdf=new Html2Pdf();
$html2pdf->writeHTML('<h1>'.$result['name'].'</h1>');
$html2pdf->output();
This is the way I connect to my database:
$mysqli=new mysqli('host', 'user', 'pass', 'db');
I have also tried adding a charset:
$mysqli->set_charset('utf8');
Or initiating the class with parameters:
$html2pdf=new Html2Pdf('P', 'A4', 'nl');
$html2pdf=new Html2Pdf('P', 'A4', 'nl', true, 'UTF8');
Other characters that are giving issues are: Ś ą ł ś
Both server and database are UTF-8.
The solution is to apply a UTF-8 font to all elements.
* { font-family:freeserif; }

How to print Arabic letters with thermal printer using Flutter esc_pos_printer library?

I'm using a printer: EPSON TM-m30
I'm currently using :
esc_pos_printer: ^4.0.3
esc_pos_utils: ^1.0.0
When I run this code
printDemoReceipt(NetworkPrinter printer) async {
printer.text('ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي');
printer.feed(2);
printer.cut();
printer.disconnect();
}
It causes this error
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid argument (string): Contains invalid characters.: "ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي"
_UnicodeSubsetEncoder.convert (dart:convert/ascii.dart:88:9)
Did anyone fix this issue?
Thank you.
Actually I have the same issue and I believe for now the only solution is to create a PDF then covert it to an image and then you can print it.
Try to
import 'dart:convert' show utf8;
printDemoReceipt(NetworkPrinter printer) async {
final arabicText = utf8.encode('ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي');
printer.textEncoded(arabicText);
printer.feed(2);
printer.cut();
printer.disconnect();
}
You have to find the character table for your printer and write the corresponding commands to let the printer know that you are printing multi byte characters such as Arabic characters. In my case, I was using sunmi printer and the only thing that worked for me was finding its character table and I wrote the commands and it worked very well. Here's a picture of what they said in the documentation.
enter image description here
And this is what I did and it worked perfectly
const utf8Encoder = Utf8Encoder();
final encodedStr = utf8Encoder.convert(invoice.description);
bytes += generator.textEncoded(Uint8List.fromList([
...[0x1C, 0x26, 0x1C, 0x43, 0xFF],
...encodedStr
]));

chatterbot twitter_trainer ASCII encoding error

I am trying to run the chatterbot's TwitterTrainer on a separate program like so:
from chatterbot import ChatBot
from chatterbot.trainers import TwitterTrainer
from settings import TWITTER
import logging
# Comment out the following line to disable verbose logging
logging.basicConfig(level=logging.INFO)
chatbot = ChatBot("TwitterBot",
logic_adapters=[
"chatterbot.logic.BestMatch"
],
input_adapter="chatterbot.input.TerminalAdapter",
output_adapter="chatterbot.output.TerminalAdapter",
database="./twitter-database.db",
twitter_consumer_key=TWITTER["CONSUMER_KEY"],
twitter_consumer_secret=TWITTER["CONSUMER_SECRET"],
twitter_access_token_key=TWITTER["ACCESS_TOKEN"],
twitter_access_token_secret=TWITTER["ACCESS_TOKEN_SECRET"],
trainer="chatterbot.trainers.TwitterTrainer",
random_seed_word="random"
)
chatbot.train()
chatbot.logger.info('Trained database generated successfully!')
And i get errors that look like that:
File "C:\Python27\lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 380, in raw_decode
obj, end = self.scan_once(s, idx) UnicodeDecodeError: 'utf8' codec can't decode byte 0x85 in position 94: invalid start byte
This program doesn't run more than 3 seconds straight, but some tweets are written to the twitter-database.db until exception occurs.
Also when looking at the trainer.py i saw this:
# TODO: Handle non-ascii characters properly
Any ideas about why this happens and how can i fix this?
Could you try to add Python Source Code Encoding top of your file # -*- coding: utf-8 -*-. These type error will occurs due to this. More information available here http://chatterbot.readthedocs.io/en/stable/encoding.html#fixing-encoding-errors

Mason2 wrong utf8 encoding with the "go" method

Bit long question, because AFAIK Poet/Mason2 isn't the very often used framework - so I'm trying to be detailed.
Two years ago I asked a question how to make Mason2 utf8 clean. As far as i know, here isn't much new in Mason/Poet in this field - and unfortunately today I meet another problem. Simple test case:
$ poet new my #create new poet application
$ cd my
Override some methods, allowing to use utf8 in the components:
add to ./lib/My/Mason/Compilation.pm
override 'output_class_header' => sub {
return join("\n",
super(), qq(
use utf8;
use Encode qw(encode decode);
)
);
};
The above adds to each compiled Mason component the use utf8....
Also need encode the output from Mason (Plack need bytes), so in: ./lib/My/Mason/Request.pm
override 'run' => sub {
my($self, $path, $args) = #_;
my $result = super();
$result->output( Encode::encode('UTF-8', $result->output()) );
return $result;
};
Now, can create a component such page.mc for example with a content:
% sub { uc($_[0]) } {{
a quick brown fox jumps over the lazy dog.
διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα.
árvíztűrő tükörfúrógép.
dość gróźb fuzją, klnę, pych i małżeństw!
эх, чужак, общий съём цен шляп (юфть) – вдрызг!
kŕdeľ šťastných ďatľov učí pri ústí váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso.
zwölf boxkämpfer jagen viktor quer über den großen sylter deich.
% }}
After running a poet app bin/run.pl you can go to: http://0:5000/page and will get a correct content.
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG. ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ
ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ. ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP. DOŚĆ GRÓŹB
FUZJĄ, KLNĘ, PYCH I MAŁŻEŃSTW! ЭХ, ЧУЖАК, ОБЩИЙ СЪЁМ ЦЕН ШЛЯП (ЮФТЬ) –
ВДРЫЗГ! KŔDEĽ ŠŤASTNÝCH ĎATĽOV UČÍ PRI ÚSTÍ VÁHU MĹKVEHO KOŇA OBHRÝZAŤ
KÔRU A ŽRAŤ ČERSTVÉ MÄSO. ZWÖLF BOXKÄMPFER JAGEN VIKTOR QUER ÜBER DEN
GROSSEN SYLTER DEICH.
But when create another component, say go.mc with a content
% $m->go('/page');
the internal redirect (the go method) somewhat mess up the content and will produce:
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG. ÎÎÎΦΥÎÎÎΤÎ
ÎÎÎÎÎΠΤΠÎΩΠΣÎΣ ÎÎ Î ÎÎÎÎÎΠΨΥΧÎÎÎ
ΤΡÎÎÎÎΤÎ. ÃRVÃZTÅ°RÅ TÃKÃRFÃRÃGÃP. DOÅÄ GRÃŹB
FUZJÄ, KLNÄ, PYCH I MAÅÅ»EÅSTW! ЭХ, ЧУÐÐÐ, ÐÐЩÐÐ
СЪÐРЦÐРШÐЯР(ЮФТЬ) â ÐÐРЫÐÐ! KÅDEĽ Å
ŤASTNÃCH ÄATĽOV UÄà PRI ÃSTà VÃHU MĹKVEHO KOÅA OBHRÃZAŤ
KÃRU A ŽRAŤ ÄERSTVà MÃSO. ZWÃLF BOXKÃMPFER JAGEN VIKTOR QUER
ÃBER DEN GROSSEN SYLTER DEICH.
Strange, the $m->visit() works correctly. So, somewhere in Poet/Mason is need do something to get correct output for the go method.
Could anyone help?
I've been working on a plugin for Mason to deal with encoding. $result->output is the wrong place to encode output, because visit will run a subrequest, encoding its own content at the end, before returning to the original component, which then re-encodes everything when it completes. So the content in the visit gets encoded twice. I'm surprised you are having a problem with go, because that discards all previous content and starts again, which should be OK.
Have a look at https://github.com/davebaird/mason-plugin-withencoding

Padrino - Sass, Coffee - Encoding::UndefinedConversionError, from ASCII-8BIT to UTF-8

How to reproduce
Gemfile
gem 'haml'
gem 'sass'
gem 'coffee-script'
app/app.rb
get '/javascripts/rus_test.js' do
content_type 'text/javascript', charset: 'utf-8'
coffee :"../../public/javascripts/rus_test"
end
public/javascripts/rus_test.coffee (it's work)
alert 'Hello World!'
localhost:3000/javascripts/rus_test.js
(function() {
alert('Hello World!');
}).call(this);
public/javascripts/rus_test.coffee (doesn't work)
alert 'Привет!'
GIVES ERROR
Encoding::UndefinedConversionError at /javascripts/rus_test.js
"\xD0" from ASCII-8BIT to UTF-8
I tried to set several variants of Encoding.default in config/boot.rb.
one of variants of boot initializing
Padrino.before_load do
Encoding.default_internal = nil
# Encoding.default_external = 'ASCII-8BIT'
end
It's work for HAML with russian text, but doesn't work for SASS and COFFEE
What should I do to fix it?
Remove ridiculous Encoding.default_internal = nil and add this code somewhere to monkey patch Tilt:
# this makes tilt to treat templates as properly encoded (respect Encoding.default_external)
module Tilt
class CoffeeScriptTemplate
def prepare
#data.force_encoding Encoding.default_external
if !options.key?(:bare) and !options.key?(:no_wrap)
options[:bare] = self.class.default_bare
end
end
end
end