diff --git a/libs/core-functions/src/functions/lib/udf_wrapper.ts b/libs/core-functions/src/functions/lib/udf_wrapper.ts index 9f214b5df..8ec6b5c72 100644 --- a/libs/core-functions/src/functions/lib/udf_wrapper.ts +++ b/libs/core-functions/src/functions/lib/udf_wrapper.ts @@ -373,6 +373,7 @@ export async function UDFTestRun({ }, region: { code: "NY", + name: "New York", }, location: { latitude: 40.6808, diff --git a/services/rotor/src/lib/maxmind.ts b/services/rotor/src/lib/maxmind.ts index 94a875408..1e4aa27f3 100644 --- a/services/rotor/src/lib/maxmind.ts +++ b/services/rotor/src/lib/maxmind.ts @@ -1,4 +1,4 @@ -import { Reader, ReaderModel, City, Isp } from "@maxmind/geoip2-node"; +import { Reader, ReaderModel, City, Isp, Names } from "@maxmind/geoip2-node"; import * as zlib from "zlib"; import * as tar from "tar"; import { Geo } from "@jitsu/protocols/analytics"; @@ -16,6 +16,8 @@ type Edition = PaidEdition | FreeEditions | "NotRequired" | ""; type LoadFunction = (edition: Edition) => Promise; +type GetLocalizedNameFunction = (names: Names) => string; + const composeURL = (licenseKeyOrURL: string, edition: Edition) => { if (licenseKeyOrURL.startsWith("http")) { return licenseKeyOrURL + (licenseKeyOrURL.endsWith("/") ? "" : "/") + edition + ".tar.gz"; @@ -68,6 +70,14 @@ export async function initMaxMindClient(opts: { } else { loadFunc = (edition: Edition) => loadFromURL(composeURL(licenseKey || url || "", edition)); } + let getLocalizedName: GetLocalizedNameFunction; + if (process.env.MAXMIND_LOCALE) { + getLocalizedName = (names: Names) => { + return names[process.env.MAXMIND_LOCALE!] || names.en; + }; + } else { + getLocalizedName = (names: Names) => names.en; + } let cityReader: ReaderModel | undefined; let countryReader: ReaderModel | undefined; @@ -136,12 +146,13 @@ export async function initMaxMindClient(opts: { continent: geo.continent ? { code: geo.continent.code, + name: getLocalizedName(geo.continent.names), } : undefined, country: geo.country ? { code: geo.country.isoCode, - name: geo.country.names.en, + name: getLocalizedName(geo.country.names), isEU: !!geo.country.isInEuropeanUnion, } : undefined, @@ -149,12 +160,13 @@ export async function initMaxMindClient(opts: { ? { code: geo.subdivisions[0].isoCode, confidence: geo.subdivisions[0].confidence, + name: getLocalizedName(geo.subdivisions[0].names), } : undefined, city: geo.city ? { confidence: geo.city.confidence, - name: geo.city.names.en, + name: getLocalizedName(geo.city.names), } : undefined, postalCode: geo.postal diff --git a/types/protocols/analytics.d.ts b/types/protocols/analytics.d.ts index 568e34281..3d4cbad60 100644 --- a/types/protocols/analytics.d.ts +++ b/types/protocols/analytics.d.ts @@ -12,12 +12,19 @@ export type WithConfidence = T & { export type Geo = { continent?: { code: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA"; + /** + * Localized name of the continent + */ + name: string; }; country?: { /** * Two-letter country code (ISO 3166-1 alpha-2): https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ code: string; + /** + * Localized name of the country + */ name: string; isEU: boolean; }; @@ -27,8 +34,15 @@ export type Geo = { * For USA it's two-letter capitaluzed state code (such as NY) */ code: string; + /** + * Localized name of the region + */ + name: string; }>; city?: WithConfidence<{ + /** + * Localized name of the city + */ name: string; }>;