Skip to content
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

feat(i18n): new locale interface, and translation configs #1710

Merged

Conversation

RiyaJethwa
Copy link
Contributor

Updates

  • Addition of locale interface
  • Ability to change modal title
  • Ability to change group and total label which was previously hardcoded
  • Ability to change toolbar labels

Demo screenshot or recording

Screenshot 2023-12-27 at 7 20 42 PM Screenshot 2023-12-27 at 7 23 14 PM Screenshot 2023-12-27 at 7 24 18 PM image

@RiyaJethwa RiyaJethwa requested review from theiliad and a team as code owners December 27, 2023 14:44
Copy link

netlify bot commented Dec 27, 2023

Deploy Preview for carbon-charts-angular ready!

Name Link
🔨 Latest commit ab1a29c
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-angular/deploys/65ca4c28d44a4400087f6577
😎 Deploy Preview https://deploy-preview-1710--carbon-charts-angular.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 27, 2023

Deploy Preview for carbon-charts-react ready!

Name Link
🔨 Latest commit ab1a29c
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-react/deploys/65ca4c284cbdd900081cacc0
😎 Deploy Preview https://deploy-preview-1710--carbon-charts-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 27, 2023

Deploy Preview for carbon-charts-core ready!

Name Link
🔨 Latest commit ab1a29c
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-core/deploys/65ca4c281f22470008ae08f5
😎 Deploy Preview https://deploy-preview-1710--carbon-charts-core.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@RiyaJethwa
Copy link
Contributor Author

I have read the DCO document and I hereby sign the DCO.

/**
* Locale configuration
*/
locale?:Locale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space after colon

date?: (value: Date) => string
translations?: {
group?: string // used by Tooltip and Toolbar / Tabular Representation
total?:string // ditto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space after colon

toolbarExportAsJPG: 'Export to JPG',
toolbarExportAsPNG: 'Export to PNG',
tabularDownloadAsCSV: 'Download as CSV'
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RiyaJethwa pls make this object a bit more organized, could be this way

{
	group: 'Group',
	total: 'Total',
        tabularRep: {
             title: "Tabular representation'",
	    downloadAsCSV: 'Download as CSV'
        },
        toolbar: {
	     exportAsCSV: 'Export to CSV',
	     exportAsJPG: 'Export to JPG',
	     exportAsPNG: 'Export to PNG',
        }
}


return format(date, formatString, { locale })
const { code, optionsObject } = localeObject
if (interval === 'quarterly') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you explain this piece pls? it seems like we're formatting date values using our number locale formatter

@@ -224,6 +224,7 @@ export class Axis extends Component {
// create the right ticks formatter
let formatter: any
const userProvidedFormatter = getProperty(axisOptions, 'ticks', 'formatter')
const { code, number: numberFormatter } = getProperty(options, 'locale')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { code, number: numberFormatter } = getProperty(options, 'locale')
const { code: localeCode, number: numberFormatter } = getProperty(options, 'locale')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls use more readable names. it's clear on this line that you're pulling a locale code, but in another line in this file when you will pass code into a function, it's not clear (from the name) what code is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll keep this in mind, I have updated to localeCode.

@@ -84,8 +84,10 @@ export function formatTick(
i: number,
allTicks: Array<number>,
interval: string,
timeScaleOptions: TimeScaleOptions
timeScaleOptions: TimeScaleOptions,
options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options
localeOptions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just pass options.locale into this function rather than the full options

@@ -18,16 +18,17 @@ export class MeterTitle extends Title {
const options = this.getOptions()
const svg = this.getComponentContainer()
const { groupMapsTo } = options.data

const meterTitle = getProperty(options, 'locale', 'translations', 'meterTitle')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to organize these better (e.g. options.locale.translations.meter.title

Comment on lines 85 to 191
},
pp: {
obj: {},
type: 'time'
},
'MMM d, p': {
obj: {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit'
},
type: 'time'
},
p: {
obj: {
hour: 'numeric',
minute: '2-digit'
},
type: 'time'
},
'MMM d, h:mm:ss.SSS a': {
obj: {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
fractionalSecondDigits: 3
},
type: 'time'
},
'h:mm:ss.SSS a': {
obj: {
hour: 'numeric',
minute: '2-digit',
fractionalSecondDigits: 3
},
type: 'time'
},
'MMM d': {
obj: {
month: 'short',
day: 'numeric'
},
type: 'date'
},
d: {
obj: {
day: 'numeric'
},
type: 'date'
},
'MMM d, hh a': {
obj: {
month: 'short',
day: 'numeric',
hour: '2-digit'
},
type: 'time'
},
'hh a': {
obj: {
hour: '2-digit'
},
type: 'time'
},
'MMM yyyy': {
obj: {
month: 'short',
year: 'numeric'
},
type: 'date'
},
MMM: {
obj: {
month: 'short'
},
type: 'date'
},
'eee, MMM d': {
obj: {
weekday: 'short',
month: 'short',
day: 'numeric'
},
type: 'date'
},
eee: {
obj: {
weekday: 'short'
},
type: 'date'
},
yyyy: {
obj: {
year: 'numeric'
},
type: 'date'
}
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this object? what does it do?

Copy link
Contributor Author

@RiyaJethwa RiyaJethwa Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are formats for date string, but this is a work in progress since it is a draft PR.

export interface Locale {
code?: string // BCP 47 language tag
number?: (value: number, language: string) => string
date?: (value: Date, language: string, options) => string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the type for options? is it Intl.DateTimeFormatOptions?

code?: string // BCP 47 language tag
number?: (value: number, language: string) => string
date?: (value: Date, language: string, options) => string
time?: (value: Date, language: string, options) => string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the type for options? is it Intl.DateTimeFormatOptions?

const binnedStackedData = this.getBinnedStackedData()

const headers = [
console.log(code)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log

@@ -217,7 +217,8 @@ export class WordCloud extends Component {
value: datum.value
},
{
label: options.tooltip.groupLabel,
label:
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel'),
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel') || 'Group',

@theiliad theiliad changed the title feat(localeInterface):addition of locale interface in options and and implementation of translations property feat(i18n): new locale interface, and translation configs Feb 8, 2024
@theiliad theiliad merged commit 60ef1ec into carbon-design-system:master Feb 13, 2024
4 checks passed
@MathiasWP
Copy link
Contributor

MathiasWP commented Feb 13, 2024

This release made our app crash when server side rendering @carbon/charts-svelte:

ReferenceError: navigator is not defined
  File "../../../../../../../../../../../../../node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@carbon/charts/dist/color-scale-utils-eeC25Jjh.mjs", line 1867, col 9, in <anonymous>
    code: navigator.language,

@nstuyvesant
Copy link
Contributor

@MathiasWP -Surprised to hear that @carbon/charts-svelte ever worked with SSR as its dependencies expect to run in a browser due to the APIs and modules it uses (html-to-image, dompurify, etc.).

I use @carbon/charts-svelte with a SvelteKit web app (adapter-node) and use export const prerender = false for routes that use the charts.

@dabrad26
Copy link
Member

I believe this PR has broken the use of numberFormatter for some charts.

numberFormatter?: (value: number) => string;

These are wrapped in a Number type which is causing NaN to be rendered for most uses.

@ManudeepHegde
Copy link

I don't understand how this PR fixed the issue posted on
#1673

Am i missing something here or it is still an open issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants