2

I want to make a ColdFusion(10) project to be global. It should support more languages,such as Japanese,Chinese,Spanish,etc. I searched on the Internet and found that it can be done easily by adding one line:

<cfprocessingDirective pageencoding="utf-8">

But it is supposed to add it in every cfc or cfms. I tried to add it in Application.cfc, but failed to display expected contents. So what can I do to support multiple languages?(utf-8)

Also, I need to think about the database part. I designed the db with strings as "nvarchar". So when I insert/set new values, I must add a 'N' before the values. Since it is an existing project, and there are thousands of written insert/set blocks. How can I add the 'N' in every existing statement efficiently?

update table 
set name = N 'name'

I really appreciate it if you say anything help.

Yuanhai Shi
  • 333
  • 1
  • 13
  • You should be using parameters. – SLaks Jun 24 '13 at 19:19
  • @SLaks Thanks for your correction. UTF-8 can be 1-4 bytes. But my question is mainly on how to handle it in ColdFusion. And what do you mean by parameters? – Yuanhai Shi Jun 24 '13 at 19:23
  • 2
    *what do you mean by parameters* You should be using `cfqueryparam` on all query parameters. It utilizes bind variables, which among other things, help protect against sql injection. For CF10, you use `cfsqltype="cf_sql_nvarchar"` rather than prepending an `N`. See also this question on the [`String Format` setting and backward compatilibity](http://stackoverflow.com/questions/10802388/what-are-the-details-for-using-cf-sql-nvarchar-in-coldfusion-10). – Leigh Jun 24 '13 at 19:30
  • @YuanhaiShi: Actually, UTF8 is 1 - 6 bytes. (for non-BMP characters) – SLaks Jun 24 '13 at 19:31
  • @YuanhaiShi: *RE I tried to add it in Application.cfc* It does not work that way. ["You must add it to each page that has a nondefault encoding."](http://www.adobe.com/support/coldfusion/internationalization/internationalization_cfmx/internationalization_cfmx3.html). I would also suggest reading a few articles on i18n first, to get an idea of what it entails. For examle: http://www.learncfinaweek.com/week1/i18n/ – Leigh Jun 24 '13 at 19:45
  • @Leigh Thanks for your comments. "cfqueryparam" is a good practice. I will use it instead of 'N'. Since there are thousands of existing parameters, is there a way to batch modify them to be cfqueryparam? – Yuanhai Shi Jun 24 '13 at 19:45
  • @YuanhaiShi unfortunately no, CFBuilder search and replace is your friend. – Henry Jun 24 '13 at 19:46
  • @Leigh Thanks for your link. I will read and study it. – Yuanhai Shi Jun 24 '13 at 19:47
  • 2
    @YuanhaiShi - These might also be helpful in identifying non-parameterized queries. [qpscanner.cfc](http://qpscanner.riaforge.org/) and [Adding cfqueryparams to a Legacy Site Without Losing Your Hair](http://www.coldfusionmuse.com/index.cfm/2008/7/26/cfqueryparam-tips-for-adding). – Leigh Jun 24 '13 at 19:54
  • @Leigh Thanks for the tools. They are very helpful. – Yuanhai Shi Jun 24 '13 at 19:59

1 Answers1

1

CF side:

CFBuilder 2 or any decent text editor would insert UTF-8 BOM for you and UTF-8 would work right away in CF. If your text editor does not support inserting BOM, then like you said, use <cfprocessingDirective> (as last resort)

SQL side:

For CF10+, you can use CF_SQL_NVARCHAR in <cfqueryparam>. ref: What are the details for using CF_SQL_NVARCHAR in ColdFusion 10?

For CF9 or below, when setting up the datasource in CF Admin, String Format -- Enable High ASCII characters and Unicode for data sources configured for non-Latin characters.

Then use of any <cfqueryparam type='CF_SQL_VARCHAR'> will be translated into N'string' by CF. However, any index built on the varchar column will not be utilized in the prepared statement.

Community
  • 1
  • 1
Henry
  • 32,689
  • 19
  • 120
  • 221
  • I am using CFBuilder 2. But How can it insert utf-8 BOM? automatically? Should I turn on something? I read similar instructions on the ColdFusion website, but I can not understand it. – Yuanhai Shi Jun 24 '13 at 19:51
  • I tried to create a new cfm file and output some Chinese characters. It can be displayed corrected. I looked at Properties of the cfm file. Found that BOM IS utf-8. But I found other existing cfms do not have this attribute. So how can I manually add "BOM" to them? Thanks. – Yuanhai Shi Jun 24 '13 at 20:03
  • CFBuilder or any Eclipse: Project Properties -> Resource -> Text file encoding: UTF-8 – Henry Jun 24 '13 at 20:05
  • For existing CFM, u can open it in CFBuilder, change something and save. BOM will be inserted. – Henry Jun 24 '13 at 20:06
  • Thanks for your patience. But I failed to get BOM inserted into existing cfm even I do change and save it in CFBuilder2.any ideas? The existing cfms were written in Dreamweaver. – Yuanhai Shi Jun 24 '13 at 20:17
  • Google for other tools that can insert BOM in batch for you. – Henry Jun 24 '13 at 21:42