9月 17, 2014
SAPページの多言語対応
ワンソースで多言語対応しないと行けないので、
簡単な言語をストックする関数を考えた。
// 辞書関数
dictionary = function(word){
this.result = '';
array = {
entryText1: 'my text 1',
entryText2: 'my text 2',
}
if( array[word] == null ){
this.result = '#No find.';
}else{
this.result = array[word];
}
return this.result
}
// 例
dictionary('entryText1'); // my text 1
// 登録されていない言葉はエラーメッセージを返す
dictionary('hoge'); // #No find.
// こんな感じで使う
var _html = '<div>'+dictionary('entryText2')+'</div>' // <div>my text 2</div>