-
Notifications
You must be signed in to change notification settings - Fork 10
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 #11 from IgniteUI/refleciton-shell-strings
Refleciton shell strings
- Loading branch information
Showing
7 changed files
with
142 additions
and
53 deletions.
There are no files selected for viewing
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,36 @@ | ||
import { name as projName} from '../package.json'; | ||
import * as path from 'path'; | ||
|
||
import { RendererEvent } from "typedoc/dist/lib/output/events"; | ||
import { Component } from 'typedoc/dist/lib/utils'; | ||
import { RendererComponent } from 'typedoc/dist/lib/output/components'; | ||
|
||
@Component({ name: 'theme-component' }) | ||
export class ThemeComponent extends RendererComponent { | ||
initialize() { | ||
this.listenTo(this.owner, { | ||
[RendererEvent.BEGIN]: this.onRenderBegin | ||
}); | ||
} | ||
|
||
private onRenderBegin() { | ||
this.registerHelpers(); | ||
} | ||
|
||
private registerHelpers() { | ||
let module; | ||
try { | ||
module = require.resolve(projName); | ||
} catch(e) { | ||
this.application.logger.error(e.message); | ||
return; | ||
} | ||
|
||
const pluginDist = path.dirname(require.resolve(module)); | ||
if (pluginDist) { | ||
this.owner.theme.resources.deactivate(); | ||
this.owner.theme.resources.helpers.addOrigin('custom-helpers', `${pluginDist}\\utils\\helpers`); | ||
this.owner.theme.resources.activate(); | ||
} | ||
} | ||
} |
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,23 @@ | ||
export class GlobalFuncs { | ||
public static getOptionValue(options, key) { | ||
const indx = options.findIndex((e) => e === `--${key}`); | ||
if (indx >= options.length - 1 || indx < 0) { | ||
return; | ||
} | ||
|
||
return options[indx + 1]; | ||
} | ||
|
||
public static getKeyValuePairRes(data, key, value) { | ||
if (!data) { | ||
return value; | ||
} | ||
|
||
if (!data[key]) { | ||
return value; | ||
} | ||
|
||
const res = data[key][value]; | ||
return res ? res : value; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import * as process from 'process'; | ||
import * as fs from 'fs-extra'; | ||
import { Constants } from '../constants'; | ||
|
||
export function localize(str) { | ||
const value = getLocalizedValue(str); | ||
if (value) { | ||
return value; | ||
} | ||
|
||
return str; | ||
} | ||
|
||
function getLocalizedValue(str) { | ||
const local = getOptionValue(Constants.LOCALIZE_OPTION); | ||
const jsonFilePath = getOptionValue(Constants.TEMPLATE_STRINGS_OPTION); | ||
const fileContent = fs.readJsonSync(jsonFilePath); | ||
|
||
if (fileContent && fileContent[local]) { | ||
return fileContent[local][str]; | ||
} | ||
|
||
return str; | ||
} | ||
|
||
function getOptionValue(key) { | ||
const indx = process.argv.findIndex((e) => e === `--${key}`); | ||
if (indx >= process.argv.length - 1) { | ||
return; | ||
} | ||
|
||
return process.argv[indx + 1]; | ||
import { GlobalFuncs } from '../global-funcs'; | ||
import { HardcodedStrings } from '../template-strings'; | ||
|
||
export function localize(options: any) { | ||
const value = options.fn(this).trim(); | ||
return GlobalFuncs.getKeyValuePairRes( | ||
HardcodedStrings.getTemplateStrings(), | ||
HardcodedStrings.getLocal(), | ||
value); | ||
} |
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,24 @@ | ||
export class HardcodedStrings { | ||
private static local: string; | ||
private static templateStrings: string; | ||
|
||
public static setLocal(local: string) { | ||
if (this.local === undefined) { | ||
this.local = local; | ||
} | ||
} | ||
|
||
public static getLocal(): string { | ||
return this.local; | ||
} | ||
|
||
public static setTemplateStrings(templateStrings: string) { | ||
if (this.templateStrings === undefined) { | ||
this.templateStrings = templateStrings; | ||
} | ||
} | ||
|
||
public static getTemplateStrings(): string { | ||
return this.templateStrings; | ||
} | ||
} |