Difference between revisions of "Gremlins"

From Lingoport Wiki
Jump to: navigation, search
(30px No Locale Framework)
(30px Static Files)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
I18n Gremlins are sneaky issues that work their way into your code and foul up localization. They can be hard for developers to recognize.
+
Internationalization Gremlins are sneaky issues that work their way into your code and foul up localization. They can be hard for developers to recognize.
   
 
= I18n Gremlins =
 
= I18n Gremlins =
 
Those gremlins sneak up in your source code.
 
Those gremlins sneak up in your source code.
= [[File:King-gremlin.png|10px]] No Locale Framework =
+
= [[File:King-gremlin.png|30px]] No Locale Framework =
 
* <b> Issues</b>: The king of all Gremlins: If the application does not have a locale framework, the Gremlin King rules and all Gremlins infest the application.
 
* <b> Issues</b>: The king of all Gremlins: If the application does not have a locale framework, the Gremlin King rules and all Gremlins infest the application.
 
* <b>Remedy</b>: Design a Locale Framework. How to detect, negotiate, persist, assign the locale for the application needs to be designed and implemented.
 
* <b>Remedy</b>: Design a Locale Framework. How to detect, negotiate, persist, assign the locale for the application needs to be designed and implemented.
 
= [[File:gremlinAsset2.png|30px]] Embedded Strings =
 
* <b> Issues</b>: A visible Gremlin: When you change locale, the string stays the same. The string was hard-coded in the application and is resistant to locale changes.
 
* <b>Remedy</b>: Externalize the Embedded String from the source code. Generate a Key/Value pair in a resource file, refer to that key in the code to retrieve the value. The value is the string itself. With your locale framework, you can then retrieve the string from a locale dependent resource file.
 
   
 
= [[File:gremlinAsset1.png|30px]] Concatenations =
 
= [[File:gremlinAsset1.png|30px]] Concatenations =
* <b> Issues</b>: A mean Gremlin: It's like an Embedded String which cannot be externalized as such. It first needs some redesign. This one comes in all kinds of shapes and sizes. Here is a concatenation example:<code> "Welcome " + username + " to our Rebel Outfitter store"</code>
+
* <b> Issues</b>: A common but mean Gremlin: It's like an Embedded String which cannot be externalized as such. It first needs some redesign. This one comes in all kinds of shapes and sizes. Here is a concatenation example:<code> "Welcome " + username + " to our Rebel Outfitter store"</code>
 
* <b>Remedy</b>: The typical remedy is to create a parameterized strings and keep the parameter variables outside of the string itself. For instance, the parameterized string may look like <code>"Welcome %{userName} to our Rebel Outfitter store"</code>.
 
* <b>Remedy</b>: The typical remedy is to create a parameterized strings and keep the parameter variables outside of the string itself. For instance, the parameterized string may look like <code>"Welcome %{userName} to our Rebel Outfitter store"</code>.
   
= [[File:gremlinAsset5.png|30px]] Static Files=
+
= [[File:gremlinAsset2.png|30px]] Embedded Strings =
* <b> Issues</b>: An annoying Gremlin: The application serves the same file, maybe a video or a legal HTML file, independently of the locale. For example, a Chinese video is shown to a Russian application user.
+
* <b> Issues</b>: A tongue-in-cheek Gremlin: When you change locale, the string stays the same. The string was hard-coded in the application and is resistant to locale changes.For example if there was simple code that looks like:
  +
String d ="All the young ones";
* <b>Remedy</b>: The locale framework needs to provide for an internationalization way to refer to the file so that a locale with a static file name will result in serving a Russian video to the Russian user.
 
  +
String e ="Having a good time";
   
  +
* <b>Remedy</b>: Externalize the Embedded String from the source code. Generate a Key/Value pair in a resource file, refer to that key in the code to retrieve the value. The value is the string itself. With your locale framework, you can then retrieve the string from a locale dependent resource file.
= [[File:gremlinAsset4.png|30px]] Date/Time Format=
 
* <b> Issues</b>: An cunning Gremlin: The application may look right but provide the wrong information. If the date shown is 05/06/07 independently of the locale, it means May 6, 2007 for an American, June 5, 2007 for a Frenchman, and 2005, June 7 for a Japanese.
 
* <b>Remedy</b>: The application needs to format the data based on the user's locale and, for instance, show a 05/06/07 to an American user, 06/05/07 to a French user, and 07/06/05 to a Japanese user for May 6, 2007. In addition, the date/time may be displayed using Time Zone. The entity or value itself may need to be a GMT date / time.
 
   
  +
When the string is externalized, the code looks like:
= [[File:gremlinAsset6.png|30px]] Currency Format=
 
  +
String d =getString("JAVA_TESTSTR_105");
* <b> Issues</b>: An greedy Gremlin: The application displays the same amount whatever the locale/region of the user. For instance, a Canadian user sees $5000 and may think that in Canadian dollars when it's in US Dollars.
 
  +
String e =getString("JAVA_TESTSTR_106");
  +
  +
And the key/value pair in the resource file looks like:
  +
JAVA_TESTSTR_105=All the young ones
  +
JAVA_TESTSTR_106=Having a good time
  +
  +
= [[File:gremlinAsset3.png|30px]] Locale Sensitive Method =
  +
=== Date/Time Format===
  +
* <b> Issues</b>: An cunning Gremlin: The application may look right but provides the wrong information. If the date shown is '''05/06/07''' independently of the locale, it means:
  +
** May 6, 2007 for an American
  +
** June 5, 2007 for a Frenchman
  +
** 2005, June 7 for a Japanese
  +
* <b>Remedy</b>: The application needs to format the data based on the user's locale and, for instance, show May 6, 2007 as
  +
**05/06/07 to an American user
  +
**06/05/07 to a French user
  +
** 07/06/05 to a Japanese user
  +
In addition, the date/time may be displayed using Time Zone. The entity or value itself may need to be a GMT date / time.
  +
  +
===Currency Format ===
  +
* <b> Issues</b>: An greedy Gremlin: The application displays the same amount whatever the locale/region of the user. For instance, a Canadian user sees '''$5000''' and may think that in Canadian dollars when it's in US Dollars.
 
* <b>Remedy</b>: The application needs to format the number, display the symbol, and most likely use some exchange rate to display the actual currency amount for the user's language / region.
 
* <b>Remedy</b>: The application needs to format the number, display the symbol, and most likely use some exchange rate to display the actual currency amount for the user's language / region.
  +
  +
= [[File:gremlinAsset4.png|30px]] General Patterns=
  +
* <b> Issues</b>: A Shape Shifter: This gremlin may take the form of a encoding like ISO8859-1 when UTF-8 is required, or set a font that cannot be used in Chinese, even decides a format output.
  +
* <b>Remedy</b>: Make sure to check for each pattern to decide if it is a General Pattern, if more need to be added to your specific application, and how to refactor the code.
  +
  +
= [[File:gremlinAsset5.png|30px]] Static Files=
  +
* <b> Issues</b>: An annoying Gremlin: The application serves the same file, maybe a video or a legal HTML file, independently of the locale. For example, a Chinese video is shown to a Russian application user. For example:
  +
placemarkAttributes.imageSource = "./img/marker.png";
  +
* <b>Remedy</b>: The locale framework needs to provide for an internationalization way to refer to the file so that a locale with a static file name will result in serving a Russian video to the Russian user.

Latest revision as of 23:49, 9 December 2019

Internationalization Gremlins are sneaky issues that work their way into your code and foul up localization. They can be hard for developers to recognize.

I18n Gremlins

Those gremlins sneak up in your source code.

King-gremlin.png No Locale Framework

  • Issues: The king of all Gremlins: If the application does not have a locale framework, the Gremlin King rules and all Gremlins infest the application.
  • Remedy: Design a Locale Framework. How to detect, negotiate, persist, assign the locale for the application needs to be designed and implemented.

GremlinAsset1.png Concatenations

  • Issues: A common but mean Gremlin: It's like an Embedded String which cannot be externalized as such. It first needs some redesign. This one comes in all kinds of shapes and sizes. Here is a concatenation example: "Welcome " + username + " to our Rebel Outfitter store"
  • Remedy: The typical remedy is to create a parameterized strings and keep the parameter variables outside of the string itself. For instance, the parameterized string may look like "Welcome %{userName} to our Rebel Outfitter store".

GremlinAsset2.png Embedded Strings

  • Issues: A tongue-in-cheek Gremlin: When you change locale, the string stays the same. The string was hard-coded in the application and is resistant to locale changes.For example if there was simple code that looks like:
 String d ="All the young ones";
 String e ="Having a good time";
  • Remedy: Externalize the Embedded String from the source code. Generate a Key/Value pair in a resource file, refer to that key in the code to retrieve the value. The value is the string itself. With your locale framework, you can then retrieve the string from a locale dependent resource file.

When the string is externalized, the code looks like:

 String d =getString("JAVA_TESTSTR_105");
 String e =getString("JAVA_TESTSTR_106");

And the key/value pair in the resource file looks like:

JAVA_TESTSTR_105=All the young ones
JAVA_TESTSTR_106=Having a good time

GremlinAsset3.png Locale Sensitive Method

Date/Time Format

  • Issues: An cunning Gremlin: The application may look right but provides the wrong information. If the date shown is 05/06/07 independently of the locale, it means:
    • May 6, 2007 for an American
    • June 5, 2007 for a Frenchman
    • 2005, June 7 for a Japanese
  • Remedy: The application needs to format the data based on the user's locale and, for instance, show May 6, 2007 as
    • 05/06/07 to an American user
    • 06/05/07 to a French user
    • 07/06/05 to a Japanese user

In addition, the date/time may be displayed using Time Zone. The entity or value itself may need to be a GMT date / time.

Currency Format

  • Issues: An greedy Gremlin: The application displays the same amount whatever the locale/region of the user. For instance, a Canadian user sees $5000 and may think that in Canadian dollars when it's in US Dollars.
  • Remedy: The application needs to format the number, display the symbol, and most likely use some exchange rate to display the actual currency amount for the user's language / region.

GremlinAsset4.png General Patterns

  • Issues: A Shape Shifter: This gremlin may take the form of a encoding like ISO8859-1 when UTF-8 is required, or set a font that cannot be used in Chinese, even decides a format output.
  • Remedy: Make sure to check for each pattern to decide if it is a General Pattern, if more need to be added to your specific application, and how to refactor the code.

GremlinAsset5.png Static Files

  • Issues: An annoying Gremlin: The application serves the same file, maybe a video or a legal HTML file, independently of the locale. For example, a Chinese video is shown to a Russian application user. For example:
   placemarkAttributes.imageSource = "./img/marker.png";
  • Remedy: The locale framework needs to provide for an internationalization way to refer to the file so that a locale with a static file name will result in serving a Russian video to the Russian user.