1.8.0 • Published 2 months ago

@volvo-cars/market-sites v1.8.0

Weekly downloads
1,552
License
UNLICENSED
Repository
github
Last release
2 months ago

@volvo-cars/market-sites

@volvo-cars/market-sites @volvo-cars/market-sites

A package providing regional and market localization data for market sites on volvocars.com, stored in a size efficient format.

It is meant to complement the Intl API and should only contain data that changes very rarely such as country names, measurement systems, etc. Some of this data is on it's way to be built in to browsers with Intl.Locale and unit preferences.

It will not provide configuration values or application specific data.

Usage

getMarketSite(siteSlug: string): MarketSite

siteSlug

  • A site slug, a URL friendly identifier of the market site (the first part of the pathname on www.volvocars.com).
  • The full pathname, e.g. location.pathname

If a site could not be found, a MarketSite with English defaults are given.

Examples

import { getMarketSite } from '@volvo-cars/market-sites';

const us = getMarketSite('us');
// {
//   "href": "/us",
//   "htmlLanguage": "en-US",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-US",
//   "localizedLanguageName": "English",
//   "marketName": "United States",
//   "multilingual": false,
//   "regionCode": "US",
//   "roadLengthUnit": "mile",
//   "siteSlug": "us",
// }

const intl = getMarketSite('/intl/cars/xc90');
// {
//   "href": "/intl",
//   "htmlLanguage": "en",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-001",
//   "localizedLanguageName": "English",
//   "marketName": "International",
//   "multilingual": false,
//   "regionCode": "001",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "intl",
// }

const arabicBaharain = getMarketSite('ar-bh');
// {
//   "href": "/ar-bh",
//   "htmlLanguage": "ar-BH",
//   "languageCode": "ar",
//   "languageDirection": "rtl",
//   "languageName": "Arabic",
//   "locale": "ar-BH",
//   "localizedLanguageName": "العربية",
//   "marketName": "Bahrain",
//   "multilingual": true,
//   "regionCode": "BH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "ar-bh",
// }

const englishBahrain = getMarketSite('en-bh');
// {
//   "href": "/en-bh",
//   "htmlLanguage": "en-BH",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-BH",
//   "localizedLanguageName": "English",
//   "marketName": "Bahrain",
//   "multilingual": true,
//   "regionCode": "BH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "en-bh",
// }

const missingSite = getMarketSite('foo');
// {
//   "href": "/",
//   "htmlLanguage": "en",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en",
//   "localizedLanguageName": "English",
//   "marketName": undefined,
//   "multilingual": undefined,
//   "regionCode": undefined,
//   "roadLengthUnit": "kilometer",
//   "siteSlug": undefined,
// }

getMarketSiteByRegionAndLanguage(regionCode: string, languageCode: string): MarketSite

Given the region and language, returns a Market Site.

regionCode

languageCode

Examples

import { getMarketSiteByRegionAndLanguage } from '@volvo-cars/market-sites';

getMarketSiteByRegionAndLanguage('CH', 'it');
//  {
//   "href": "/it-ch",
//   "htmlLanguage": "it-CH",
//   "languageCode": "it",
//   "languageDirection": "ltr",
//   "languageName": "Italian",
//   "locale": "it-CH",
//   "localizedLanguageName": "italiano",
//   "marketName": "Switzerland",
//   "multilingual": true,
//   "regionCode": "CH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "it-ch",
// }

getMarketSitesByRegion(regionCode: string): MarketSite[]

Returns an array of all available sites for a given market/region.

regionCode

Examples

const swissSites = getMarketSitesByRegion('CH');
// [
//   {
//     "href": "/fr-ch",
//     "htmlLanguage": "fr-CH",
//     "languageCode": "fr",
//     "languageDirection": "ltr",
//     "languageName": "French",
//     "locale": "fr-CH",
//     "localizedLanguageName": "français",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "fr-ch",
//   },
//   {
//     "href": "/de-ch",
//     "htmlLanguage": "de-CH",
//     "languageCode": "de",
//     "languageDirection": "ltr",
//     "languageName": "German",
//     "locale": "de-CH",
//     "localizedLanguageName": "Deutsch",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "de-ch",
//   },
//   {
//     "href": "/it-ch",
//     "htmlLanguage": "it-CH",
//     "languageCode": "it",
//     "languageDirection": "ltr",
//     "languageName": "Italian",
//     "locale": "it-CH",
//     "localizedLanguageName": "italiano",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "it-ch",
//   },
// ]

getAllMarketSites(): MarketSite[]

Returns an array of all available market sites.

validateSiteSlug(siteSlug?: string): void

Throws an error if siteSlug is not a valid market site slug.

isValidSiteSlug(siteSlug?: string): boolean

Returns true/false if siteSlug is a valid site slug.

MarketSite

class MarketSite {
  /**
   * URL to the home page of the market site.
   */
  href: string;

  /**
   * A locale that's only includes the region suffix if required to distinguish
   * between different market sites. Suitable for `<html lang="">`.
   */
  htmlLanguage: string;

  /**
   * Name of the market site language in English.
   */
  languageName: string;

  /**
   * Name of the market site language in the native language.
   */
  localizedLanguageName: string;

  /**
   * Writing direction of the market site language.
   */
  languageDirection: 'ltr' | 'rtl';

  /**
   * The ISO 639-1 or ISO-639-2 language code part of the locale without script or region.
   *
   * Useful for some APIs that don't accept locales with regions.
   */
  languageCode: string;

  /**
   * A Unicode BCP 47 locale identifier consisting of
   *
   *  - An ISO 639-1 language code (e.g. 'en')
   *  - (optionally) a script code (e.g. 'Latn')
   *  - A region (or country) code (e.g. 'US')
   *
   * This is what you should use with browser APIs such as `Intl`.
   */
  locale: string;

  /**
   * Unique URL friendly identifier of the market site.
   * The first part of the pathname on www.volvocars.com.
   */
  siteSlug: string | undefined;

  /**
   * Region or country name in English.
   *
   * Usually a country, with exceptions such as Hong Kong (China) and Special Sales markets.
   */
  marketName: string | undefined;

  /**
   * Region or country code, e.g. US, SE.
   */
  regionCode: string | undefined;

  /**
   * Whether or not the market/region has more sites in different languages.
   */
  multilingual: boolean | undefined;

  /**
   * Road length unit for region.
   */
  roadLengthUnit: 'mile' | 'kilometer';
}
1.8.0

2 months ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.4

3 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago