Merged PR 21999: support configuration of locale · Gilbert00254/PowerBI-JavaScript@ced5998 · GitHub
Skip to content

Commit ced5998

Browse files
committed
Merged PR 21999: support configuration of locale
support configuration of locale
1 parent 1c8a6c8 commit ced5998

10 files changed

Lines changed: 142 additions & 24 deletions

File tree

dist/powerbi-client.d.ts

Lines changed: 26 additions & 2 deletions

dist/powerbi.js

Lines changed: 39 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
44
"description": "JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and responding to data selection.",
55
"main": "dist/powerbi.js",
66
"typings": "dist/powerbi-client.d.ts",

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const config = {
2-
version: '2.3.2',
2+
version: '2.3.3',
33
type: 'js'
44
};
55

src/embed.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface IEmbedConfiguration {
3535
uniqueId?: string;
3636
embedUrl?: string;
3737
accessToken?: string;
38-
settings?: models.ISettings;
38+
settings?: IEmbedSettings;
3939
pageName?: string;
4040
filters?: models.IFilter[];
4141
pageView?: models.PageView;
@@ -49,6 +49,15 @@ export interface IEmbedConfiguration {
4949
width?: number;
5050
}
5151

52+
export interface ILocaleSettings {
53+
language?: string;
54+
formatLocale?: string;
55+
}
56+
57+
export interface IEmbedSettings extends models.ISettings {
58+
localeSettings?: ILocaleSettings;
59+
}
60+
5261
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
5362
uniqueId: string;
5463
type: string;
@@ -382,7 +391,7 @@ export abstract class Embed {
382391
this.config = utils.assign({ settings }, config);
383392
this.config.uniqueId = this.getUniqueId();
384393
this.config.embedUrl = this.getEmbedUrl();
385-
394+
this.addLocaleToEmbedUrl(config);
386395
if(this.embeType === 'create') {
387396
this.createConfig = {
388397
datasetId: config.datasetId || this.getId(),
@@ -401,6 +410,24 @@ export abstract class Embed {
401410
}
402411
}
403412

413+
/**
414+
* Adds locale parameters to embedUrl
415+
*
416+
* @private
417+
* @param {IEmbedConfiguration} config
418+
*/
419+
private addLocaleToEmbedUrl(config: IEmbedConfiguration): void {
420+
if (!config.settings) {
421+
return;
422+
}
423+
let localeSettings = config.settings.localeSettings
424+
if (localeSettings && localeSettings.language) {
425+
this.config.embedUrl = utils.addParamToUrl(this.config.embedUrl, 'language', localeSettings.language);
426+
}
427+
if (localeSettings && localeSettings.formatLocale) {
428+
this.config.embedUrl = utils.addParamToUrl(this.config.embedUrl, 'formatLocale', localeSettings.formatLocale);
429+
}
430+
}
404431

405432
/**
406433
* Gets an embed url from the first available location: options, attribute.

src/tile.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ export class Tile extends embed.Embed {
1515
static allowedEvents = ["tileClicked", "tileLoaded"];
1616

1717
constructor(service: service.Service, element: HTMLElement, config: embed.IEmbedConfiguration) {
18-
let url = config.embedUrl;
19-
const urlParamMatch = url.indexOf("?") > 0;
20-
let firstParamSign = urlParamMatch ? '&' : '?';
21-
url = url + firstParamSign + 'dashboardId=' + config.dashboardId + '&tileId=' + config.id;
22-
config.embedUrl = url;
18+
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'dashboardId', config.dashboardId);
19+
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'tileId', config.id);
2320

2421
super(service, element, config);
2522
Array.prototype.push.apply(this.allowedEvents, Tile.allowedEvents);

src/util.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,18 @@ export function assign(...args) {
107107
export function createRandomString(): string {
108108
return (Math.random() + 1).toString(36).substring(7);
109109
}
110+
111+
/**
112+
* Adds a parameter to the given url
113+
*
114+
* @export
115+
* @param {string} url
116+
* @param {string} paramName
117+
* @param {string} value
118+
* @returns {string}
119+
*/
120+
export function addParamToUrl(url: string, paramName: string, value: string): string {
121+
let parameterPrefix = url.indexOf('?') > 0 ? '&' : '?';
122+
url += parameterPrefix + paramName + '=' + value;
123+
return url;
124+
}

test/test.spec.ts

Lines changed: 23 additions & 0 deletions

0 commit comments

Comments
 (0)