From 530e445756a6ebd111ecde4bb0d7f7b1135ab93d Mon Sep 17 00:00:00 2001 From: Heath Nielson Date: Wed, 3 Apr 2013 12:33:47 -0600 Subject: [PATCH 1/3] Fix a problem with getString when the string property is a sub-property. --- src/strings.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/strings.js b/src/strings.js index 16f2df8a..22a4cb48 100644 --- a/src/strings.js +++ b/src/strings.js @@ -45,12 +45,14 @@ $.extend( $, { var props = prop.split('.'), string = null, args = arguments, + container = I18N, i; - for ( i = 0; i < props.length; i++ ) { + for ( i = 0; i < props.length-1; i++ ) { // in case not a subproperty - string = I18N[ props[ i ] ] || {}; + container = container[ props[ i ] ] || {}; } + string = container[ props[ i ] ]; if ( typeof( string ) != "string" ) { string = ""; From d16eb04a8ac9d3b61e6bf8086c973b574c984e15 Mon Sep 17 00:00:00 2001 From: Heath Nielson Date: Fri, 26 Apr 2013 15:18:27 -0600 Subject: [PATCH 2/3] Fix setStrings() with the same fix as getStrings(). Initialize container to I18N. --- src/strings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strings.js b/src/strings.js index 22a4cb48..7d990237 100644 --- a/src/strings.js +++ b/src/strings.js @@ -75,7 +75,7 @@ $.extend( $, { setString: function( prop, value ) { var props = prop.split('.'), - container = $.Strings, + container = I18N, i; for ( i = 0; i < props.length - 1; i++ ) { From e98fb410ee93f1c722ff3ccf93e712566bb7e5e4 Mon Sep 17 00:00:00 2001 From: Heath Nielson Date: Fri, 26 Apr 2013 15:19:23 -0600 Subject: [PATCH 3/3] Add some get/setString tests. --- test/strings.js | 29 +++++++++++++++++++++++++++++ test/test.html | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/strings.js diff --git a/test/strings.js b/test/strings.js new file mode 100644 index 00000000..61a12d93 --- /dev/null +++ b/test/strings.js @@ -0,0 +1,29 @@ +(function() { + + module("strings"); + test("getSubString", function() { + equal(OpenSeadragon.getString("Errors.Dzi"), + "Hmm, this doesn't appear to be a valid Deep Zoom Image.", + "Read sub-string"); + }); + + test("getInvalidString", function() { + equal(OpenSeadragon.getString("Greeting"), "", + "Handled unset string key"); + equal(OpenSeadragon.getString("Errors"), "", + "Handled requesting parent key"); + }); + + test("setString", function() { + OpenSeadragon.setString("Greeting", "Hello world"); + equal(OpenSeadragon.getString("Greeting"), "Hello world", + "Set a string"); + }); + + test("setSubString", function() { + OpenSeadragon.setString("CustomGreeting.Hello", "Hello world"); + equal(OpenSeadragon.getString("CustomGreeting.Hello"), "Hello world", + "Set a sub-string"); + }); + +})(); diff --git a/test/test.html b/test/test.html index 37a9afe4..6ca53fa2 100644 --- a/test/test.html +++ b/test/test.html @@ -16,5 +16,6 @@ + - \ No newline at end of file +