From deebe017e77dfefb32743b4ae0d0c3767aab8586 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 7 Aug 2017 14:54:44 -0700 Subject: [PATCH 1/2] vis: Add types for Options.locales --- types/vis/index.d.ts | 29 ++++++++++++++++++++++++++++- types/vis/vis-tests.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/types/vis/index.d.ts b/types/vis/index.d.ts index 2b71d3d6d6..1a967d65c6 100644 --- a/types/vis/index.d.ts +++ b/types/vis/index.d.ts @@ -1703,6 +1703,33 @@ export interface Edge { id?: IdType; } +export interface Locales { + [language: string]: LocaleMessages | undefined; + en?: LocaleMessages; + de?: LocaleMessages; + es?: LocaleMessages; + it?: LocaleMessages; + nl?: LocaleMessages; + 'pt-br'?: LocaleMessages; + ru?: LocaleMessages; +} + +export interface LocaleMessages { + edit?: string; + del?: string; + back?: string; + addNode?: string; + addEdge?: string; + editNode?: string; + editEdge?: string; + addDescription?: string; + edgeDescription?: string; + editEdgeDescription?: string; + createEdgeError?: string; + deleteClusterError?: string; + editClusterError?: string; +} + export interface Options { autoResize?: boolean; @@ -1712,7 +1739,7 @@ export interface Options { locale?: string; - locales?: string[]; + locales?: Locales; clickToUse?: boolean; diff --git a/types/vis/vis-tests.ts b/types/vis/vis-tests.ts index 354f766cb0..a4e9d1d6f8 100644 --- a/types/vis/vis-tests.ts +++ b/types/vis/vis-tests.ts @@ -190,3 +190,30 @@ const options2 = { }; network.setOptions(options2); + +// +// Test code sample from http://visjs.org/docs/network/#locales +// +var locales = { + en: { + edit: 'Edit', + del: 'Delete selected', + back: 'Back', + addNode: 'Add Node', + addEdge: 'Add Edge', + editNode: 'Edit Node', + editEdge: 'Edit Edge', + addDescription: 'Click in an empty space to place a new node.', + edgeDescription: 'Click on a node and drag the edge to another node to connect them.', + editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.', + createEdgeError: 'Cannot link edges to a cluster.', + deleteClusterError: 'Clusters cannot be deleted.', + editClusterError: 'Clusters cannot be edited.' + } +} +options = { + locale: 'en', + locales: locales, +} + +network.setOptions(options); From dbfe8a1688064178aa06cec6de587d7b5b43b563 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 8 Aug 2017 08:57:29 -0700 Subject: [PATCH 2/2] Make All LocaleMessages properties required Also fix lint. --- types/vis/index.d.ts | 26 +++++++++++++------------- types/vis/vis-tests.ts | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/types/vis/index.d.ts b/types/vis/index.d.ts index 1a967d65c6..b55adc6ac8 100644 --- a/types/vis/index.d.ts +++ b/types/vis/index.d.ts @@ -1715,19 +1715,19 @@ export interface Locales { } export interface LocaleMessages { - edit?: string; - del?: string; - back?: string; - addNode?: string; - addEdge?: string; - editNode?: string; - editEdge?: string; - addDescription?: string; - edgeDescription?: string; - editEdgeDescription?: string; - createEdgeError?: string; - deleteClusterError?: string; - editClusterError?: string; + edit: string; + del: string; + back: string; + addNode: string; + addEdge: string; + editNode: string; + editEdge: string; + addDescription: string; + edgeDescription: string; + editEdgeDescription: string; + createEdgeError: string; + deleteClusterError: string; + editClusterError: string; } export interface Options { diff --git a/types/vis/vis-tests.ts b/types/vis/vis-tests.ts index a4e9d1d6f8..263baffc79 100644 --- a/types/vis/vis-tests.ts +++ b/types/vis/vis-tests.ts @@ -194,7 +194,7 @@ network.setOptions(options2); // // Test code sample from http://visjs.org/docs/network/#locales // -var locales = { +const locales = { en: { edit: 'Edit', del: 'Delete selected', @@ -210,10 +210,10 @@ var locales = { deleteClusterError: 'Clusters cannot be deleted.', editClusterError: 'Clusters cannot be edited.' } -} +}; options = { locale: 'en', - locales: locales, -} + locales, +}; network.setOptions(options);