在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):tryggvigy/pseudo-localization开源软件地址(OpenSource Url):https://github.com/tryggvigy/pseudo-localization开源编程语言(OpenSource Language):HTML 96.2%开源软件介绍(OpenSource Introduction):Inspired by pseudo-localization at Netflix and Firefox pseudo-localization
Demo here. Changing text nodes and adding or removing trees of elements will trigger a pseudo-localization run on all the new text added to the DOM. Try it yourself by changing text or adding/removing elements using the devtools. InstallationThrough npm
Raw script (without npm)Copy paste the files in Usageimport or require the npm module
import pseudoLocalization from 'pseudo-localization';
// Or using CommonJS
// const pseudoLocalization = require('pseudo-localization').default;
pseudoLocalization.start();
// Later, if needed
pseudoLocalization.stop(); To use import React from 'react';
import pseudoLocalization from 'pseudo-localization';
class PseudoLocalization extends React.Component {
componentDidMount() {
pseudoLocalization.start();
}
componentWillUnmount() {
pseudoLocalization.stop();
}
}
// And use it
class Page extends React.Component {
render() {
return (
<main>
<PseudoLocalization />
<h1>I will get pseudo localized along with everything else under document.body!</h1>
<main>
);
}
} Using hooks? Here's an example: import React from 'react';
import pseudoLocalization from 'pseudo-localization';
function PseudoLocalization() {
React.useEffect(() => {
pseudoLocalization.start();
return () => {
pseudoLocalization.stop()
};
}, []);
}
// And use it
function Page() {
return (
<main>
<PseudoLocalization />
<h1>I will get pseudo localized along with everything else under document.body!</h1>
<main>
);
} You can also call the underlying import { localize } from 'pseudo-localization';
// Or using CommonJS
// const { localize } = require('pseudo-localization');
console.log(localize('hello')); // --> ħḗḗŀŀǿǿ
console.log(localize('hello', { strategy: 'bidi' })); // --> oʅʅǝɥ A good use-case for import { localize } from 'pseudo-localization';
import translate from './my-translation-lib';
// Pseudo localize every string returned from your normal translation function.
const _ = key => localize(translate(key, navigator.language));
_('Some Localized Text'); // Şǿǿḿḗḗ Ŀǿǿƈȧȧŀīẑḗḗḓ Ŧḗḗẋŧ
// Or, in React for example
const Header = () => <h1>{_('Localized Header Text')}</h1>; Any strings that do not pass through the translation function will now stand out in the UI because the will not be pseudo-localized. Strategies
accented - Ȧȧƈƈḗḗƞŧḗḗḓ ḖḗƞɠŀīīşħUsage: In Accented English all Latin letters are replaced by accented Unicode counterparts which don't impair the readability of the content. This allows developers to quickly test if any given string is being correctly displayed in its 'translated' form. Additionally, simple heuristics are used to make certain words longer to better simulate the experience of international users. bidi - ɥsıʅƃuƎ ıpıԐUsage: Bidi English is a fake RTL locale. All words are surrounded by Unicode formatting marks forcing the RTL directionality of characters. In addition, to make the reversed text easier to read, individual letters are flipped. Why?To catch localization problems like:
In addition, the pseudo-localization process may uncover places where an element should be localizable, but is hard coded in a source language. Docs
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论