1

I made application that read some words from TXT file and put them into database. The problem is: when I get words from other languages (that have some 'non english' letters) it looks like this: enter image description here It is possible to store these characters in js variable? It's not necessary to show them in console, but they have to be correct in database.

EDIT:

It isn't a problem with code editor, loading from file or database. It is a problem with node.js. When I try to show it:

console.log("ąężźćó");

these characters are shown as "?" too. It is not a problem with cmd, because I tried to save this string to database and result is the same (and I'm 100% sure that this database can store these characters).

Piotrek
  • 10,919
  • 18
  • 73
  • 136
  • Save and render as UTF8 – mplungjan Jan 19 '14 at 21:09
  • 1
    I use both notepad++ and sublime, they both accept unicode (and UTF8 is the default) I don't have to do anything. – damphat Jan 19 '14 at 21:17
  • In what format (encoding) are the text files? What format does your database accept? And in what format does your node script deal with them? Somewhere there must be a mistake, please provide the necessary details to get an answer. – Bergi Jan 19 '14 at 21:23
  • Make sure the files are opened using the same encoding in NodeJS as they were saved. http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback `fs.readFile(filename, 'utf8', callback)` for example. – WiredPrairie Jan 19 '14 at 21:29
  • to loading file I use "line-by-line" module https://npmjs.org/package/line-by-line (because this file is really big) but I set there encoding to utf-8 – Piotrek Jan 19 '14 at 21:33
  • it is not database, code editor or txt file blame. All of them works good with these characters. It must be something with node – Piotrek Jan 19 '14 at 21:35
  • yes, this is probably node.js fault, when i try to show part of this file using console.log, these characters don't be shown. – Piotrek Jan 19 '14 at 21:38
  • as a recomendation: use linux or osx for developing Node.JS apps, in Windows there are a lot of issues and this one of them, just use ”Lucida Console” font and it will be fine. – micnic Jan 20 '14 at 13:58

2 Answers2

1

Javascript should have no issues storing those characters.

I tried it on my mac terminal and it worked fine so I don't think it's node:

> console.log("ąężźćó");
ąężźćó
undefined
> 

But, I see you're using the windows cmd shell. There might be other issues but at a minimum, you will likely need to set the code page of the windows cmd shell to utf-8

See: Unicode characters in Windows command line - how?

From that post:

chcp 65001
Also, you need to use Lucida console fonts
Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • but, if js has no issues storing those characters, why it sends to database these "wrong ones" ("?" instead of ę). My database is MySQL, I use phpmyadmin to manage data in it. When I add manually some data, all characters are right, when I use node.js - it doesn't work – Piotrek Jan 20 '14 at 14:14
  • Your question and the answer covered the console display. To answer why your node code interfacing with the db is having an issue, you will need to ask that as a question and post some code. – bryanmac Jan 20 '14 at 15:51
0

latin-2 chars? in utf-8? looks like a bad encoding (one byte is shown, where is the second one?) This mix will not work.

@Ludwik11 which characters encoding do you use in your mysql connection (jeśli spytać wolno)