fiftyone.ipintelligence.translation
v4.5.102
Published
Country translation engines for the 51Degrees on-premise IP Intelligence SDK. Turns the weighted ISO country code lists into localized, ordered country name lists.
Readme
Node IP Intelligence Country Translation
Introduction
This project contains 51Degrees IP Intelligence country translation engines that can be used with the Pipeline API.
This package - fiftyone.ipintelligence.translation
The on-premise IP Intelligence engine returns country information as weighted lists of ISO country codes. This package adds the two translation engines that turn those codes into localized country names and produce complete, ordered lists of every country, so a demo can render a dropdown of countries with the most probable country at the top.
CountryCodeTranslationEngine(element data keycountrynames) translates the weightedCountryCodesGeographical/CountryCodesPopulationlists from the IP intelligence engine (element data keyip) into the English country namesCountryNamesGeographical/CountryNamesPopulation, preserving the weights.CountriesTranslationEngine(element data keycountrynamestranslated) translates the English names into the browser language and builds the ordered "All" lists. For each dimension it produces the weighted translated names (CountryNames...Translated), the complete ordered names (CountryNames...AllTranslated) and the index-aligned codes (CountryCodes...All). The weighted countries lead, ordered by descending weight, followed by every remaining country alphabetically by translated name.
The translation YAML files (countrycodes.en_GB.yml and countries.<locale>.yml) are read from the cxx/data/ip-intelligence/Translations folder of the data submodule that ships with fiftyone.ipintelligence.onpremise. A different directory can be supplied to a builder via the translationsPath option.
This package builds on the generic fiftyone.pipeline.translation base.
It can be used like this:
const {
CountryCodeTranslationEngineBuilder,
CountriesTranslationEngineBuilder
} = require('fiftyone.ipintelligence.translation');
const pipeline = new IpIntelligenceOnPremisePipelineBuilder({ dataFile })
.add(new CountryCodeTranslationEngineBuilder().build())
.add(new CountriesTranslationEngineBuilder().build())
.build();
const flowData = pipeline.createFlowData();
flowData.evidence.add('query.client-ip', '8.8.8.8');
flowData.evidence.add('header.accept-language', 'fr-FR');
await flowData.process();
const result = flowData.get('countrynamestranslated');
const codes = result.get('countrycodesgeographicalall').value;
const names = result.get('countrynamesgeographicalalltranslated').value;Installation
npm install fiftyone.ipintelligence.translationTests
To run tests you will need to install the jest library.
npm install jest --globalThen, navigate to the module directory and execute:
npm testFind out more
- IP Intelligence
- IP Intelligence documentation
- Getting started
- Pricing
- https://github.com/51Degrees/51degrees-node
