Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

638 B
Raw Blame
import regions from '../../../public/iso-3166-2.json';
import { useCountryNames } from './useCountryNames';

export function useRegionNames(locale: string) {
  const { countryNames } = useCountryNames(locale);

  const getRegionName = (regionCode: string, countryCode?: string) => {
    if (!countryCode) {
      return regions[regionCode];
    }

    if (!regionCode) {
      return null;
    }

    const region = regionCode?.includes('-') ? regionCode : `${countryCode}-${regionCode}`;

    return regions[region] ? `${regions[region]}, ${countryNames[countryCode]}` : region;
  };

  return { regionNames: regions, getRegionName };
}