Skip to main content

SQL Server - Multi language data support

Problem:

I used CKEditor to edit my pages. Then, I stored the content of the pages to SQL Server 2008 database. The page contents should support in different languages such as English, German and Vietnamese. I met a problem when I worked on Vietnamese pages.
The text was successfully saved but it was displayed wrong when reading again from database, likes the following:
Input: "Ðây là Tiếng Việt"
Display: "Ðây là Ti?ng Vi?t".

Solution:

We need to use nvarchar (nchar | ntext) data type for strings  and we also need to precede all unicode strings with 'N'

Here is my code:
 
--create table 
CREATE TABLE [dbo].[xedu_page_content](
  [id] [numeric](11, 0) IDENTITY(1,1) NOT NULL,
  [category] [varchar](100) NOT NULL PRIMARY KEY,
  [content] [Ntext] NULL
 )

 --save
 BEGIN TRAN
 IF not exists (SELECT category FROM xedu_page_content
       WHERE category='"+in.categoryKey+"')
  INSERT INTO xedu_page_content(category,content)
   VALUES ('"+in.categoryKey+"',N'"+in.content+"');
 ELSE
  UPDATE xedu_page_content
   SET content = N'"+in.content+"'
   WHERE category='"+in.categoryKey+"'
 COMMIT

Reference:
[1]. http://stackoverflow.com/questions/2017198/sql-server-multi-language-data-support
[2]. http://msdn.microsoft.com/en-us/library/ms186939.aspx

Comments

Popular posts from this blog

The HelloWorld example of JSF 2.2 with Myfaces

I just did by myself create a very simple app "HelloWorld" of JSF 2.2 with a concrete implementation Myfaces that we can use it later on for our further JSF trying out. I attached the source code link at the end part. Just follow these steps below: 1. Create a Maven project in Eclipse (Kepler) with a simple Java web application archetype "maven-archetype-webapp". Maven should be the best choice for managing the dependencies , so far. JSF is a web framework that is the reason why I chose the mentioned archetype for my example. 2. Import dependencies for JSF implementation - Myfaces (v2.2.10) into file pom.xml . The following code that is easy to find from  http://mvnrepository.com/  with key words "myfaces". <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-api</artifactId> <version>2.2.10</version> </dependency> <dependency> <groupId>org.apache.myfaces.core<...

Styling Sort Icons Using Font Awesome for Primefaces' Data Table

So far, Primefaces has used image sprites for displaying the sort icons. This leads to a problem if we want to make a different style for these icons; for example, I would make the icon "arrow up" more blurry at the first time the table loading because I want to highlight the icon "arrow down". I found a way that I can replace these icons with Font Awesome icons. We will use "CSS Pseudo-classes" to achieve it. The hardest thing here is that we should handle displaying icons in different cases. There is a case both "arrow up" and "arrow down" showing and other case is only one of these icons is shown. .ui-sortable-column-icon.ui-icon.ui-icon-carat-2-n-s { background-image: none; margin-left: 5px; font-size: 1.1666em; position: relative; } .ui-sortable-column-icon.ui-icon.ui-icon-carat-2-n-s:not(.ui-icon-triangle-1-s)::before { content: "\f106"; font-family: "FontAwesome"; position: ...

Gzip upload on browsers

Today, I faced a problem that I could not upload my archive file with gzip format on Firefox, even it worked on Chrome. I was using macOS. My application had a setting to whitelist accepted files. I’ve already added "application/gzip" to that list. "It’s strange!", I thought. I finally figured out that my uploaded file's type actually was "application/x-gzip" on Firefox. I also asked my colleagues to check their uploaded files on Window and Ubuntu. Hmm… they were totally different! It was "application/x-compressed" on Window, and was "application/x-compressed-tar" on Ubuntu. In fact, gzip is already standardized by IANA. There is a note in RFC-6713 as below: "Some applications have informally used media types such as application/gzip-compressed, application/gzipped, application/x-gunzip, application/x-gzip, application/x-gzip-compressed, and gzip/document to describe data compressed with gzip. The media types defin...

The culture war at the heart of open source

I enjoyed reading this post: https://words.steveklabnik.com/the-culture-war-at-the-heart-of-open-source Here is my highlight: If you ask a random developer what “open source” means to them, you won’t often hear “software that follows the Open Source Definition.” If you ask them “what’s the difference between free software and open source software,” you’ll often hear “aren’t those the same thing?” or “you can charge money for open source software, it’s not always free.” You may even hear “it’s on GitHub.” In brief, there was a man Richard Stallman (and his team) starting a project called "GNU Project" in 1983. This project was about to develop a free software system. The term "free" here meant "freedom", not only about the price. The Free Software Foundation appeared to support this project. But then, the term "free software" was so ambiguous. "In addition, the ambiguity of the term “free software” was seen as discouraging busine...

From JSP to AngularJS

Our team maintained a project that was used a quite old web technology  JSP . Our project likes a web portal that can contain some other smaller projects, I called it a module. Now, our customers want to add a new module into it. We met a problem is the current projects can't be testable and hard to maintain because both the logic and GUI are mixed together by using JSP and JSTL. It was really a messy project structure. Therefore, we didn't want to continue this approach. Testing is very important, as well as a good structure for maintenance. We would like to apply MVC pattern for testable and maintainable ability purpose. Yeah, that was actually time for changes. Our project structure can't be testable and has poor structure. We listed out some options: Refactoring all current modules -- terrible approach, too much efforts, too risky due to a lot of modules. Using MVC just for the new modules with Servlet for C ontroller, Java class for M odel and JSP for V i...