Internationalization and localization tools


Locale-Sensitive JavaScript NodeJS Method

buf.slice([start[, end]]);

Internationalization (I18n) Method Overview

The buf.slice method returns a new buffer that references the same memory as the original, but offset and cropped by the start and end indices.

For Example:
const buf1 = Buffer.allocUnsafe(26);

for (var i = 0 ; i < 26 ; i++) {
	buf1[i] = i + 97; // 97 is ASCII a
}

const buf2 = buf1.slice(0, 3);
buf2.toString('ascii', 0, buf2.length);
	// Returns: 'abc'

buf1[0] = 33;
buf2.toString('ascii', 0, buf2.length);
	// Returns : '!bc'
							

Click here for additional details.

I18n Issues

If the buffer contains a string, then the start and end parameters may be based upon the number of string characters passed. Some unicode characters require more bytes to encode than others. If some of the characters passed require more bytes to encode, then the size will be incorrect.

Suggested Replacement

If providing a start or end setting for a string buffer, calculate the bytelength of the desired sections relevant to the encoding used. Do not assume the bytelength will be directly proportional to the number of string characters.

Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.



Locale-Sensitive JavaScript Methods

 

Lingoport internationalization and localization services and software