Internationalization and localization tools


Locale-Sensitive JavaScript NodeJS Method

buf.fill(value[, offset[, end]][, encoding]);

Internationalization (I18n) Method Overview

The buf.fill method fills the buffer with the specified value. If an offset or end are given, then only part of the buffer will be filled.



For Example:
const b = Buffer.allocUnsafe(50).fill('h');
console.log(b.toString());
  // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

Buffer(3).fill('\u0222');
// Prints: 
				

Click here for additional details.

I18n Issues

If the buffer contains a string, the start and end locations in the buffer may be based upon the number of string characters passed. However, different unicode characters may require varying amounts of bytes to encode. If some of the characters passed require more bytes to encode, then the start and end locations will be incorrect.

If the buffer contains a string, then the encoding must be correct for the context.

Suggested Replacement

If providing start and end locations for string buffers, 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.

If the buffer contains a string, check that an encoding is passed. Confirm that the encoding is correct for the application setup.

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