franc by Titus Wormer exists to answer one question – what language is this string written in? And no, this time we aren’t talking about programming languages (although I’m sure there’s a module for that as well). This time we are talking real world, human languages that existed long before semi-conductors were invented. Having hard time imagining how things worked back then, I’m not going speculate about it. Today, you can use franc to tell you which dictionary to pull off the shelf… or something other far more useful.
npm install franc
Usage
franc comes basically in two flavors. It can simply tell your with most confidence what language a passed string is in and alternatively, it can give you a list sorted by confidence/weight.
var franc = require('franc');
console.log(franc('')); // "und"
// returns single best guess
console.log(franc('Alle menslike wesens word vry')); // "afr"
console.log(franc('এটি একটি ভাষা একক IBM স্ক্রিপ্ট')); // "ben"
console.log(franc('Alle mennesker er født frie og')); // "nno"
// returns all guesses sorted by weight
console.log(franc.all('O Brasil caiu 26 posições em'));
// returns all guesses sorted by weight that are on the white list
console.log(franc.all('O Brasil caiu 26 posições em', {
'whitelist' : ['por', 'src', 'glg', 'spa']
}));
What Else?
franc support over 175 languages and can also be built for the client as evident in the online demo.
So how could one use franc? For example, you could do proper currency and number formatting by guessing the language of existing text. You could use franc to correctly route support requests to the person who speaks the language. Can you think of other usages?
Finally, checkout the runnable example and github example repository.