@salesforcedevs/docs-components 0.55.9-docs-more-locales-1 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2020, Salesforce.com, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "0.55.9-docs-more-locales-1",
3
+ "version": "0.56.0",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -24,5 +24,5 @@
24
24
  "@types/lodash.orderby": "^4.6.7",
25
25
  "@types/lodash.uniqby": "^4.7.7"
26
26
  },
27
- "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
27
+ "gitHead": "cfcb715307699fdbf36426a1a3d3cd2c899f6240"
28
28
  }
@@ -19,6 +19,12 @@ export enum HistoryState {
19
19
  REPLACE_STATE = "replaceState"
20
20
  }
21
21
 
22
+ export type Labels = {
23
+ language_english: string;
24
+ language_japanese: string;
25
+ toc_title: string;
26
+ };
27
+
22
28
  export type TreeNode = {
23
29
  label: string;
24
30
  name: string;
@@ -8,18 +8,22 @@ import {
8
8
  DocumentData,
9
9
  DocLanguage,
10
10
  DocVersion,
11
+ Labels,
11
12
  TreeNode
12
13
  } from "./types";
13
- import { Language } from "typings/custom";
14
- import { getLanguageDisplayTextById } from "dxUtils/language";
14
+
15
+ const LOCALE_TO_LABEL = {
16
+ "en-us": "language_english",
17
+ "ja-jp": "language_japanese"
18
+ };
15
19
 
16
20
  export class FetchContent {
17
21
  private apiDomain: string;
18
- private languages: Array<Language> = [];
22
+ private labels: Labels;
19
23
 
20
- constructor(apiDomain: string, languages: Array<Language>) {
24
+ constructor(apiDomain: string, labels: Labels) {
21
25
  this.apiDomain = apiDomain;
22
- this.languages = languages;
26
+ this.labels = labels;
23
27
  }
24
28
 
25
29
  async fetchDocumentData(docId: string): Promise<DocumentData | null> {
@@ -144,10 +148,11 @@ export class FetchContent {
144
148
  }
145
149
 
146
150
  private normalizeLanguage(language: ApiDocLanguage): DocLanguage {
147
-
151
+ const labelKey = language.locale && LOCALE_TO_LABEL[language.locale];
148
152
  return (
149
153
  language && {
150
- label: getLanguageDisplayTextById(this.languages, language.locale) ||
154
+ label:
155
+ (labelKey && this.labels && this.labels[labelKey]) ||
151
156
  language.label,
152
157
  id: language.locale,
153
158
  code: language.code,
@@ -1,10 +1,11 @@
1
1
  import { api, track } from "lwc";
2
- import { normalizeBoolean } from "dxUtils/normalizers";
2
+ import { normalizeBoolean, toJson } from "dxUtils/normalizers";
3
3
  import { FetchContent } from "./utils";
4
4
  import {
5
5
  CoveoAdvancedQueryXMLConfig,
6
6
  DocLanguage,
7
7
  DocVersion,
8
+ Labels,
8
9
  TreeNode,
9
10
  Header,
10
11
  HistoryState,
@@ -12,8 +13,6 @@ import {
12
13
  } from "./types";
13
14
  import { SearchSyncer } from "docUtils/SearchSyncer";
14
15
  import { LightningElementWithState } from "docBaseElements/lightningElementWithState";
15
- import { Language } from "typings/custom";
16
- import { DEFAULT_LANGUAGES } from "dxUtils/constants";
17
16
 
18
17
  // TODO: Imitating from actual implementation as doc-content use it like this. We should refactor it later.
19
18
  const handleContentError = (error): void => console.log(error);
@@ -28,14 +27,12 @@ export default class DocXmlContent extends LightningElementWithState<{
28
27
  @api coveoPublicAccessToken!: string;
29
28
 
30
29
  @api
31
- get allLanguages(): Array<Language> {
32
- return this._allLanguages;
30
+ get labels() {
31
+ return this._labels;
33
32
  }
34
33
 
35
- set allLanguages(value: string) {
36
- if (value) {
37
- this._allLanguages = JSON.parse(value);
38
- }
34
+ set labels(value) {
35
+ this._labels = toJson(value);
39
36
  }
40
37
 
41
38
  @api
@@ -47,6 +44,7 @@ export default class DocXmlContent extends LightningElementWithState<{
47
44
  this._enableCoveo = normalizeBoolean(value);
48
45
  }
49
46
 
47
+ private _labels: Labels = null;
50
48
  private availableLanguages: Array<DocLanguage> = [];
51
49
  private availableVersions: Array<DocVersion> = [];
52
50
  private contentProvider: FetchContent;
@@ -100,7 +98,6 @@ export default class DocXmlContent extends LightningElementWithState<{
100
98
  shouldStopPropagation: true,
101
99
  target: window
102
100
  });
103
- private _allLanguages: Array<Language> = DEFAULT_LANGUAGES;
104
101
 
105
102
  @track private pageReference: PageReference = {};
106
103
 
@@ -123,10 +120,8 @@ export default class DocXmlContent extends LightningElementWithState<{
123
120
  window.location.href = "/docs";
124
121
  return;
125
122
  }
126
- this.contentProvider = new FetchContent(
127
- this.apiDomain,
128
- this.allLanguages
129
- );
123
+
124
+ this.contentProvider = new FetchContent(this.apiDomain, this._labels);
130
125
  this.fetchDocument().then(() => (this.loaded = true));
131
126
  window.addEventListener("popstate", this.handlePopState);
132
127
 
@@ -213,11 +208,16 @@ export default class DocXmlContent extends LightningElementWithState<{
213
208
  }
214
209
 
215
210
  private get coveoAdvancedQueryConfig(): CoveoAdvancedQueryXMLConfig {
216
- return {
211
+ const config: { locale: string; topicid: string; version?: string } = {
217
212
  locale: this.languageId,
218
- version: this.releaseVersionId,
219
213
  topicid: this.deliverable
220
214
  };
215
+
216
+ if (this.releaseVersionId && this.releaseVersionId !== "noversion") {
217
+ config.version = this.releaseVersionId;
218
+ }
219
+
220
+ return config;
221
221
  }
222
222
 
223
223
  private get pageHeader(): Header {