i18n-pseudo

Pseudolocalization is an incredibly useful tool for localizing your
apps. This module makes it easy to apply pseudo to any given string.

If the provided string is an ICU Message formatted string, it will parse and generate the ICU Message with proper pseudo.

Given string:             some_fun_string123
Pseudo Translated string: 世界ṧỗṃệ_ḟűņ_ṧẗříņĝ①②③à𝐉𝚠𝕎ĤẗȟĈŤ你好

Features

Conversion of alphanumeric characters: Alphanumeric characters are converted into a unicode counterpart.

Ignore brackets/tokens: Characters inside angle brackets and curly braces are ignored.

Given string:             The quick brown fox <i>jumped</i> over the lazy {animal}.
Pseudo Translated string: Ťȟệ ⓠűíċǩ ḃřỗ𝚠ņ ḟỗẍ <i>ǰűṃṗệḋ</i> ỗṿệř ẗȟệ ḻàẓẙ {animal}.ṃřà𝐉𝚠𝕎ĤẗȟĈŤĈṺàẌĤẌǩ你好

Ignore interpolation operator: The character following interpolation operator is ignored.

Given string:             Hello, my name is %s and I am %d years old.
Pseudo Translated string: 世界Ĥệḻḻỗ, ṃẙ ņàṃệ íṧ %s àņḋ Ĩ àṃ %d ẙệàřṧ ỗḻḋ.ṃřà𝐉𝚠𝕎ĤẗȟĈŤ你好

Expand Text Length: Append additional pseudo translated characters based current text length.

Challenge Characters: Prepends/appends unicode characters.

Installation

Go version 1.16 or higher is required (Downloads).

Build the dependency:

go get -u github.com/fetch-rewards/i18n-pseudo

Usage

package main

import (
	"fmt"
	
	"github.com/fetch-rewards/i18n-pseudo/pseudo"
)

func main() {
	// Out of the box Pseudo Translator
	pseudoFmt := pseudo.New(pseudo.FormatOptions{})
	fmtStr := pseudoFmt.Format("my desired string")
	fmt.Println(fmtStr)

	
	// Using FormatOptions for Pseudo Translator
	pseudoOptFmt := pseudo.New(pseudo.FormatOptions{
		AppendChars: ">>",
		ExpandChars: "++",
		PrependChars: "<<",
		PseudoChars: map[rune]rune{
			'a': 'ā',
			'e': 'ē',
			'i': 'ī',
			'o': 'ō',
			'u': 'ũ',
		},
		TargetExpansion: 1.2,
	})

	fmtStr = pseudoOptFmt.Format("my desired string")
	fmt.Println(fmtStr)
}

FormatOptions

Property Default Description
AppendChars "世界" When provided, these characters will be appended to the output. This is helpful when you have certain characters that always seem to give your system trouble.
PreventExpansion false When true, will not expand the input. Expanding characters is useful to ensure your codebase accounts for move verbose languages.
ExpandChars Alphabetical characters, upper and lower case A string of characters that will be randomly selected to create an expansion of the input string.
PrependChars "你好" When provided, these characters will be prepended to the output. This is helpful when you have certain characters that always seem to give your system trouble.
PseudoChars Reference A hash map of the pseudo characters that will replace the ASCII characters. For default value, see the json value in the pseudo_chars.json file.
TargetExpansion 1.2 When provided, the length of the result will be appended with random characters based on the TargetExpansion.

TODO

  • Provide a CLI option to pseudo translate a string.

How To Contribute

You can create an issue or open a pull request.

Contributors

Avatar User
David Bacisin
Lam Doan
Aaron Presley

Inspired by i18n-pseudo-js.