-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(device-contexts): Add function that returns a more detailed desc of a language #26558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {Fragment} from 'react'; | ||
import styled from '@emotion/styled'; | ||
import * as Sentry from '@sentry/react'; | ||
import moment from 'moment-timezone'; | ||
|
||
import {t} from 'app/locale'; | ||
import plugins from 'app/plugins'; | ||
import ConfigStore from 'app/stores/configStore'; | ||
import space from 'app/styles/space'; | ||
import {defined} from 'app/utils'; | ||
|
||
|
@@ -63,6 +65,39 @@ export function getRelativeTimeFromEventDateCreated( | |
); | ||
} | ||
|
||
// Typescript doesn't have types for DisplayNames yet and that's why the type assertion "any" is needed below. | ||
// There is currently an open PR that intends to introduce the types https://github.com/microsoft/TypeScript/pull/44022 | ||
export function getFullLanguageDescription(locale: string) { | ||
const sentryAppLanguageCode = ConfigStore.get('languageCode'); | ||
|
||
const [languageAbbreviation, countryAbbreviation] = locale.includes('_') | ||
? locale.split('_') | ||
: locale.split('-'); | ||
|
||
try { | ||
const languageNames = new (Intl as any).DisplayNames(sentryAppLanguageCode, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be good to comment here about the |
||
type: 'language', | ||
}); | ||
|
||
const languageName = languageNames.of(languageAbbreviation); | ||
|
||
if (countryAbbreviation) { | ||
const regionNames = new (Intl as any).DisplayNames(sentryAppLanguageCode, { | ||
type: 'region', | ||
}); | ||
|
||
const countryName = regionNames.of(countryAbbreviation.toUpperCase()); | ||
|
||
return `${languageName} (${countryName})`; | ||
} | ||
|
||
return languageName; | ||
} catch (error) { | ||
Sentry.captureException(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with how many browsers have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind seems okay https://caniuse.com/mdn-javascript_builtins_intl_displaynames_displaynames |
||
return locale; | ||
} | ||
} | ||
|
||
const RelativeTime = styled('span')` | ||
color: ${p => p.theme.subText}; | ||
margin-left: ${space(0.5)}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you ever get a name like
a-b-c
, you're gonna be in trouble. Could that happen?