Skip to content
This repository

Read resource bundle files as UTF-8 #82

Merged
merged 2 commits into from 9 months ago

2 participants

Seb Duggan John Whish
Seb Duggan

Change behaviour of java loading of resource bundle files so language files load correctly.

This applies in particular to non-Roman alphabets - in my case, the requirement was for Chinese.

added some commits September 03, 2012
Seb Duggan Read resource bundle files as UTF-8
Change behaviour of java loading of resource bundle files so language files load correctly.

This applies in particular to non-Roman alphabets - in my case, the requirement was for Chinese.
4596e3c
Seb Duggan Use UTF-8 to include localized JS file
Using CFINCLUDE to include the .js file will not read it in UTF8 format, so change to use a CFFILE.
fc79624
John Whish
Collaborator

Hi Seb, this looks great. Would you mind adding a unit test which loads a Chinese resource file?

John Whish aliaspooryorik merged commit 5798142 into from July 30, 2013
John Whish aliaspooryorik closed this July 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Sep 03, 2012
Seb Duggan Read resource bundle files as UTF-8
Change behaviour of java loading of resource bundle files so language files load correctly.

This applies in particular to non-Roman alphabets - in my case, the requirement was for Chinese.
4596e3c
Sep 04, 2012
Seb Duggan Use UTF-8 to include localized JS file
Using CFINCLUDE to include the .js file will not read it in UTF8 format, so change to use a CFFILE.
fc79624
This page is out of date. Refresh to see the latest.
18  ValidateThis/client/jQuery/ClientScriptWriter_jQuery.cfc
@@ -52,17 +52,17 @@
52 52
 		<cfargument name="locale" type="Any" required="no" default="" />
53 53
 
54 54
 		<cfset var theScript = "" />
  55
+		<cfset var content = "" />
55 56
 
56 57
 		<cfsavecontent variable="theScript">
57  
-			<cfoutput>
58  
-				<cfif Len(arguments.locale) and ListFirst(arguments.locale,"_") NEQ "en">
59  
-					<script type="text/javascript">
60  
-					/*<![CDATA[*/
61  
-					<cfinclude template="JS/localization/messages_#ListFirst(arguments.locale,'_')#.js">
62  
-					/*]]>*/
63  
-					</script>
64  
-				</cfif>
65  
-			</cfoutput>
  58
+			<cfif Len(arguments.locale) and ListFirst(arguments.locale,"_") NEQ "en">
  59
+				<script type="text/javascript">
  60
+				/*<![CDATA[*/
  61
+				<cffile action="read" file="#getDirectoryFromPath(getCurrentTemplatePath())#/JS/localization/messages_#ListFirst(arguments.locale,'_')#.js" variable="content" charset="utf-8">
  62
+				<cfoutput>#content#</cfoutput>
  63
+				/*]]>*/
  64
+				</script>
  65
+			</cfif>
66 66
 		</cfsavecontent>
67 67
 		<cfreturn theScript />
68 68
 
5  ValidateThis/util/ResourceBundle.cfc
@@ -78,6 +78,7 @@ methods in this CFC:
78 78
 			var isOk=false; // success flag
79 79
 			var rB = createObject("java", "java.util.PropertyResourceBundle");
80 80
 			var fis=createObject("java", "java.io.FileInputStream");
  81
+			var isr=createObject("java", "java.io.InputStreamReader");
81 82
 			var keys=""; // var to hold rb keys
82 83
 			var resourceBundle=structNew(); // structure to hold resource bundle
83 84
 			var thisKey="";
@@ -85,13 +86,15 @@ methods in this CFC:
85 86
 			if (RBFileExists(arguments.rbFile)) {
86 87
 				isOk=true;
87 88
 				fis.init(arguments.rbFile);
88  
-				rB.init(fis);
  89
+				isr.init(fis, "UTF8");
  90
+				rB.init(isr);
89 91
 				keys=rB.getKeys();
90 92
 				while (keys.hasMoreElements()) {
91 93
 					thisKEY=keys.nextElement();
92 94
 					thisMSG=rB.handleGetObject(thisKey);
93 95
 					resourceBundle[thisKEY]=thisMSG;
94 96
 				}
  97
+				isr.close();
95 98
 				fis.close();
96 99
 			}
97 100
 		</cfscript>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.