-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Microsoft/API_1.4_add_locale
Api 1 4 add locale
- Loading branch information
Showing
11 changed files
with
2,572 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"PBI_API_VERSION": "v1.4.0", | ||
"type": "object", | ||
"properties": { | ||
"cranPackages": { | ||
"type": "array", | ||
"description": "An array of the Cran packages required for the custom R visual script to operate", | ||
"items": { | ||
"$ref": "#/definitions/cranPackage" | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"cranPackage": { | ||
"type": "object", | ||
"description": "cranPackage - Defines the name and displayName of a required Cran package", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "The name for this Cran package" | ||
}, | ||
"displayName": { | ||
"type": "string", | ||
"description": "The name for this Cran package that is shown to the user" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"description": "A url for package documentation in Cran website" | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"url" | ||
], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"PBI_API_VERSION": "v1.4.0", | ||
"type": "object", | ||
"properties": { | ||
"apiVersion": { | ||
"type": "string", | ||
"description": "Version of the IVisual API" | ||
}, | ||
"author": { | ||
"type": "object", | ||
"description": "Information about the author of the visual", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Name of the visual author. This is displayed to users." | ||
}, | ||
"email": { | ||
"type": "string", | ||
"description": "E-mail of the visual author. This is displayed to users for support." | ||
} | ||
} | ||
}, | ||
"assets": { | ||
"type": "object", | ||
"description": "Assets used by the visual", | ||
"properties": { | ||
"icon": { | ||
"type": "string", | ||
"description": "A 20x20 png icon used to represent the visual" | ||
} | ||
} | ||
}, | ||
"externalJS": { | ||
"type": "array", | ||
"description": "An array of relative paths to 3rd party javascript libraries to load", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"style" : { | ||
"type": "string", | ||
"description": "Relative path to the stylesheet (less) for the visual" | ||
}, | ||
"capabilities": { | ||
"type": "string", | ||
"description": "Relative path to the visual capabilities json file" | ||
}, | ||
"visual": { | ||
"type": "object", | ||
"description": "Details about this visual", | ||
"properties": { | ||
"description": { | ||
"type": "string", | ||
"description": "What does this visual do?" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "Internal visual name" | ||
}, | ||
"displayName": { | ||
"type": "string", | ||
"description": "A friendly name" | ||
}, | ||
"externals": { | ||
"type": "array", | ||
"description": "External files (such as JavaScript) that you would like to include" | ||
}, | ||
"guid": { | ||
"type": "string", | ||
"description": "Unique identifier for the visual" | ||
}, | ||
"visualClassName": { | ||
"type": "string", | ||
"description": "Class of your IVisual" | ||
}, | ||
"icon": { | ||
"type": "string", | ||
"description": "Icon path" | ||
}, | ||
"version": { | ||
"type": "string", | ||
"description": "Visual version" | ||
}, | ||
"gitHubUrl": { | ||
"type": "string", | ||
"description": "Url to the github repository for this visual" | ||
}, | ||
"supportUrl": { | ||
"type": "string", | ||
"description": "Url to the support page for this visual" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Localizing your Custom Visuals | ||
|
||
Visuals can now know PowerBI's locale, so they can display localized information | ||
(read more about [Supported languages and countries/regions for Power BI](https://powerbi.microsoft.com/en-us/documentation/powerbi-supported-languages/)).<br> | ||
The `locale` string is passed on `IVisualHost`. | ||
|
||
See [commit - UPDATE THIS!!!](https://github.com/Microsoft/PowerBI-visuals-sampleBarChart/commit/a521bc6b9930f630861dc08e27330030766ae057) for what was added at this step. | ||
|
||
## Localizing the tooltips | ||
|
||
In the sample we display the current locale in the tooltip. | ||
|
||
![Sample BarChart with Locale](./images/LocaleInSampleBarChart.png) | ||
|
||
Each of these bar charts was created under different locale (English, Basque and Hindi). | ||
|
||
The BarChart contructor now has a `locale` member which is instantiated in the constructor with the host `locale` instance. | ||
|
||
```typescript | ||
private locale: string; | ||
... | ||
this.locale = options.host.locale; | ||
``` | ||
|
||
A `LocalizaionResources` interface was added, which helps in localizing strings. It defines the required string for each locale, and also the 'defaultValue', which will be displayed if the visual wansn't adapted to this locale.<br> | ||
`myResources` is an instance of this interface, which holds the localized strings: | ||
|
||
```typescript | ||
module powerbi.extensibility.visual { | ||
|
||
export var myResources: Resources = {}; | ||
myResources["LanguageKey"] = { | ||
defaultValue: "English(English)", | ||
localization: { | ||
"ar-SA": "العربية (Arabic)", | ||
"bg-BG": "български (Bulgarian)", | ||
..., | ||
"zh-CN": "中国 (Chinese-Simplified)", | ||
"zh-TW": "中國 (Chinese-Tranditional)" | ||
} | ||
}; | ||
|
||
} | ||
``` | ||
Getting a localized string is easy using `getLocalizedString`. | ||
```typescript | ||
/** | ||
* Returns the localized string in the locale transfared using the key that was given to serch the resources | ||
* | ||
* @param {string} locale - the locale in which PowerBI is currently running | ||
* @param {object} key - specify a key for the string you want localized in your visual | ||
*/ | ||
export function getLocalizedString(locale: string, key: string): string { | ||
return myResources && key && myResources[key] && (((myResources[key]).localization[locale])|| (myResources[key]).defaultValue); | ||
} | ||
``` | ||
|
||
The data for the tooltip is than derived from the current `locale`: | ||
|
||
```typescript | ||
private getTooltipData(value: any): VisualTooltipDataItem[] { | ||
let language = getLocalizedString(this.locale,"LanguageKey"); | ||
return [{ | ||
displayName: value.category, | ||
value: value.value.toString(), | ||
color: value.color, | ||
header: language && "displayed language " + language | ||
}]; | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module powerbi.extensibility.visual { | ||
|
||
export interface Localization { | ||
"ar-SA": string; | ||
"bg-BG": string; | ||
"ca-ES": string; | ||
"cs-CZ": string; | ||
"da-DK": string; | ||
"de-DE": string; | ||
"el-GR": string; | ||
"en-US": string; | ||
"es-ES": string; | ||
"et-EE": string; | ||
"eU-ES": string; | ||
"fi-FI": string; | ||
"fr-FR": string; | ||
"gl-ES": string; | ||
"he-IL": string; | ||
"hi-IN": string; | ||
"hr-HR": string; | ||
"hu-HU": string; | ||
"id-ID": string; | ||
"it-IT": string; | ||
"ja-JP": string; | ||
"kk-KZ": string; | ||
"ko-KR": string; | ||
"it-LT": string; | ||
"lv-LV": string; | ||
"ms-MY": string; | ||
"nb-NO": string; | ||
"nl-NL": string; | ||
"pl-PL": string; | ||
"pt-BR": string; | ||
"pt-PT": string; | ||
"ro-RO": string; | ||
"ru-RU": string; | ||
"sk-SK": string; | ||
"sl-SI": string; | ||
"sr-Cyrl-RS": string; | ||
"sr-Latn-RS": string; | ||
"sv-SE": string; | ||
"th-TH": string; | ||
"tr-TR": string; | ||
"uk-UA": string; | ||
"vi-VN": string; | ||
"zh-CN": string; | ||
"zh-TW": string; | ||
} | ||
|
||
export interface LocalizaionResources { | ||
defaultValue: string; | ||
localization: Localization; | ||
} | ||
|
||
export interface Resources { | ||
[key: string]: LocalizaionResources; | ||
} | ||
|
||
/** | ||
* Returns the localized string in the locale transfared using the key that was given to serch the resources | ||
* | ||
* @param {string} locale - the locale in which PowerBI is currently running | ||
* @param {object} key - specify a key for the string you want localized in your visual | ||
*/ | ||
export function getLocalizedString(locale: string, key: string): string { | ||
return myResources && key && myResources[key] && (((myResources[key]).localization[locale])|| (myResources[key]).defaultValue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module powerbi.extensibility.visual { | ||
|
||
export var myResources: Resources = {}; | ||
myResources["LanguageKey"] = { | ||
defaultValue: "English(English)", | ||
localization: { | ||
"ar-SA": "العربية (Arabic)", | ||
"bg-BG": "български (Bulgarian)", | ||
"ca-ES": "català (Catalan)", | ||
"cs-CZ": "čeština (Czech)", | ||
"da-DK": "dansk (Danish)", | ||
"de-DE": "Deutsche (German)", | ||
"el-GR": "ελληνικά (Greek)", | ||
"en-US": "English (English)", | ||
"es-ES": "español service (Spanish)", | ||
"et-EE": "eesti (Estonian)", | ||
"eU-ES": "Euskal (Basque)", | ||
"fi-FI": "suomi (Finnish)", | ||
"fr-FR": "français (French)", | ||
"gl-ES": "galego (Galician)", | ||
"he-IL": "עברית (Hebrew)", | ||
"hi-IN": "हिन्दी (Hindi)", | ||
"hr-HR": "hrvatski (Croatian)", | ||
"hu-HU": "magyar (Hungarian)", | ||
"id-ID": "Bahasa Indonesia (Indonesian)", | ||
"it-IT": "italiano (Italian)", | ||
"ja-JP": "日本の (Japanese)", | ||
"kk-KZ": "Қазақ (Kazakh)", | ||
"ko-KR": "한국의 (Korean)", | ||
"it-LT": "Lietuvos (Lithuanian)", | ||
"lv-LV": "Latvijas (Latvian)", | ||
"ms-MY": "Bahasa Melayu (Malay)", | ||
"nb-NO": "norsk (Norwegian)", | ||
"nl-NL": "Nederlands (Dutch)", | ||
"pl-PL": "polski (Polish)", | ||
"pt-BR": "português (Portuguese)", | ||
"pt-PT": "português (Portuguese)", | ||
"ro-RO": "românesc (Romanian)", | ||
"ru-RU": "русский (Russian)", | ||
"sk-SK": "slovenský (Slovak)", | ||
"sl-SI": "slovenski (Slovenian)", | ||
"sr-Cyrl-RS": "српски (Serbian)", | ||
"sr-Latn-RS": "srpski (Serbian)", | ||
"sv-SE": "svenska (Swedish)", | ||
"th-TH": "ไทย (Thai)", | ||
"tr-TR": "Türk (Turkish)", | ||
"uk-UA": "український (Ukrainian)", | ||
"vi-VN": "tiếng Việt (Vietnamese)", | ||
"zh-CN": "中国 (Chinese-Simplified)", | ||
"zh-TW": "中國 (Chinese-Tranditional)" | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters