Globalyzer Concatenation

From Lingoport Wiki
Revision as of 18:41, 5 November 2015 by Olibouban (talk | contribs) (User Interface)
Jump to: navigation, search

UNDER EMBARGO

Introduction

What is String Concatenation?

String concatenation is widely used in software programming. String concatenation is the operation of joining two character strings end-to-end For example:

String hi = “Hello ” + “World!”;

Another example:

System.out.print(“Hello “);
System.out.println(“World!”);


A typical usage is with a variable in the middle of a string:

String ua = user +“ is ”+ age + “ years old.”;

Why is String Concatenation an Internationalization Issue?

The strings "is" and " years old." could be externalized into two resources in a resource bundle, for example in a file named resources.properties:

RES1= years old.
RES2=Title
RES3=Navigate
RES4=is

If a translator ends up with four segments to translate, the overall sentence is lost. Furthermore, even if the translator could translate it correctly, the word order is different by languages, the grammar is different too. For instance, in French, a person has four years. Without the context of the full sentence, a translator could not guess where "is" will be used.

For applications which need to execute in different locales, strings which are visible to the user should not be concatenated. Some feedback from Lingoport clients on this particular problem, before being internationalized properly:

  • “We get a lot of questions from our L10N vendor” 
  • “Our biggest trouble area is fragmented strings in the resource bundle.  At first, my team was just going along happily externalizing  […]”
  • “We have a lot of cases where there is a variable in the middle of the string” 
  • “We end up with two strings in the resources bundle rather than one string with a token for the variable piece of content”

Proper String Formatting for Internationalization

Most programming languages support some kind of parameter substitution. This mechanism can be used to refactor concatenation into proper resources. For instance, you could have a string like "{0} is {1} years old." for a Java string using the MessageFormat class to replace parameter '0' with the value of 'user' and parameter '1' with the value of 'age'. The resource in the resource bundle would then look like the following:

RES1={0} is {1} years old.
RES2=Title
RES3=Navigate

The French translator can then make use of the context and create the corresponding French .properties file:

RES1={0} a {1} ans.
RES2=Titre
RES3=Naviguer

Concatenation Detection in Globalyzer

Starting with Globalyzer 5, String Concatenation will be marked with a C priority on detected strings according to the following rules:

  • String literal either begins or ends with white space.
   String myString = " this";
   String myString2 = "that ";
  • String literal is preceded or followed by a concatenation operator. Concatenation operators vary by language. <LIST OF CONCATENATION OPS TO BE FILLED IN>
    • In Java, the concatenation operators are "+" and "+=".
   String myString3 = "hello" + " "
   myString3 += "there";
  • The String literal is a parameter to an Locale Sensitive Method with priority 0.
    • InJava, concat and append are LSMs with priority 0.
   myString3.append("something");
   myString3.concat("another thing");

Type of Rules

Example

Code Snippet



This snippet of code does have strings.

Rule

The String Method Filter rule would be configured the following way:

  • Name: '
  • Pattern: '
  • Class or Variable Type(s): '
  • Description: '
  • Help Page: <blank>

The String Method Detection rule would be configured the following way:

  • Name: '
  • Pattern: '
  • Class or Variable Type(s): '
  • Description: '
  • Help Page: <blank>

Result

When the rules are applied:

  • The string
  • The string