Skip to content

Commit

Permalink
stop translating 2 letter words to flags
Browse files Browse the repository at this point in the history
  • Loading branch information
notwaldorf committed Jun 10, 2017
1 parent 1aa1a26 commit b4778c4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion emoji-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ function getAllEmojiForWord(originalWord) {
(words && words.indexOf(maybeSingular) >= 0) ||
(words && words.indexOf(maybePlural) >= 0) ||
(words && words.indexOf(maybeVerbed) >= 0)) {
useful.push(allEmoji[emoji].char);
// If it's a two letter word that got translated to a flag, it's 99% of the
// time incorrect, so stop doing that.
if (!(word.length == 2 && allEmoji[emoji].category == 'flags')) {
useful.push(allEmoji[emoji].char);
}
}
}
return (useful.length === 0) ? '' : useful;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "MIT",
"homepage": "https://github.com/notwaldorf/emoji-translate#readme",
"dependencies": {
"emojilib": "^2.2.1"
"emojilib": "^2.0.0"
},
"devDependencies": {
"tape": "^4.6.3",
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ test('translate', function (t) {

t.end();
});

test('annoying translations', function(t) {
// these should not be flags.
t.equal('im', translate.translate('im').trim());
t.equal('in', translate.translate('in').trim());
t.equal('is', translate.translate('is').trim());
t.equal('am', translate.translate('am').trim());

// hi should work
t.notEqual('hi', translate.translate('hi').trim());
t.end();
});

0 comments on commit b4778c4

Please sign in to comment.