Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from manifoldjs/shouldLocalizeFixes
Browse files Browse the repository at this point in the history
Localization Fixes, set for relase of 0.6.1 of big manifold
  • Loading branch information
boyofgreen authored Jul 20, 2016
2 parents 08cb04d + 9299a36 commit 3aedf93
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 263 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Microsoft Edge Extension platform module for [ManifoldJS](https://github.com/man

NodeJS: Install [nodejs](https://nodejs.org/) - NodeJS includes npm

Git: Install [git](https://git-scm.com/) - This is needed to insall the ManifoldJS-EdgeExtension Platform until an npm package is published

Windows 10 SDK: Included in [Visual Studio](https://www.visualstudio.com/) or Install the [standalone SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk)

### ManifoldJS
Expand All @@ -21,20 +19,13 @@ From a shell with node / npm installed
npm install -g manifoldjs
```

### Add ManifoldJS-EdgeExtension Platform

From a shell with node / npm / git installed
```
manifoldjs platform add edgeextension https://github.com/MicrosoftEdge/manifoldjs-edgeextension.git
```

## Usage

### Generate appxmanifest.xml and extension directory structure from manifest.json

From a shell with node / npm installed
```
manifoldjs -m "<PATH TO EXTENSION DIRECTORY>/manifest.json" -p edgeextension
manifoldjs -m "<PATH TO EXTENSION DIRECTORY>/manifest.json" -p edgeextension -f edgeextension [-l debug]
```


Expand Down Expand Up @@ -90,7 +81,7 @@ Square150x150Logo and Square44x44Logo
### Generate the Appx Package
From a shell with node / npm installed
```
manifoldjs package <EXTENSION NAME>/edgeextension/manifest
manifoldjs package <EXTENSION NAME>/edgeextension/manifest [-l debug]
```

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/appxmanifest-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14287.0" MaxVersionTested="12.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14800.0" />
</Dependencies>

<Resources>
Expand Down
23 changes: 23 additions & 0 deletions lib/assets/priconfig-template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<index root="\" startIndexAt="\">
<default>
<qualifier name="Language" value="{default_locale}"/>
<qualifier name="Contrast" value="standard"/>
<qualifier name="Scale" value="100"/>
<qualifier name="HomeRegion" value="001"/>
<qualifier name="TargetSize" value="256"/>
<qualifier name="LayoutDirection" value="LTR"/>
<qualifier name="Theme" value="dark"/>
<qualifier name="AlternateForm" value=""/>
<qualifier name="DXFeatureLevel" value="DX9"/>
<qualifier name="Configuration" value=""/>
<qualifier name="DeviceFamily" value="Universal"/>
<qualifier name="Custom" value=""/>
</default>
<indexer-config type="folder" foldernameAsQualifier="true" filenameAsQualifier="true" qualifierDelimiter="."/>
<indexer-config type="resw" convertDotsToSlashes="true" initialPath=""/>
<indexer-config type="resjson" initialPath=""/>
<indexer-config type="PRI"/>
</index>
</resources>
34 changes: 30 additions & 4 deletions lib/localize.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var acceptedLanguageCodes = ["ar", "ar-sa", "ar-ae", "ar-bh", "ar-dz", "ar-eg",

function shouldLocalize(extManifest) {
var localizeResources = false;
if (!extManifest.hasOwnProperty("default_locale"))
return false;

if (extManifest.name.indexOf(MsgKey) == 0) {
localizeResources = true;
Expand Down Expand Up @@ -60,7 +62,7 @@ function getResources(extManifest, localesList) {
var resourceTemplate = "<Resource Language=\"" + resourceKey + "\" />"
var resourceString = "";

if (shouldLocalize(extManifest)) {
if (shouldLocalize(extManifest)) {
var defaultLocale = mapLocalesFromI18nToUWP(extManifest.default_locale);
if (typeof defaultLocale == "undefined")
throw new Error('Default Locale cannot be mapped to a store locale.');
Expand All @@ -77,7 +79,7 @@ function getResources(extManifest, localesList) {
resourceString += resourceTemplate.replace(resourceKey, currentLocale);
}
}
else {
else {
resourceString = resourceTemplate.replace(resourceKey, "en-us");
}

Expand Down Expand Up @@ -189,11 +191,11 @@ function makePriConfig(priConfigFilePath, extManifest) {
}

if (!extManifest.hasOwnProperty("default_locale"))
return "No defualt_local in the extension manifest: MakePriConfig failed";
return Q.reject(new Error('No defualt_local in the extension manifest: MakePriConfig failed'));

var defaultLocale = mapLocalesFromI18nToUWP(extManifest.default_locale);
if (typeof defaultLocale == "undefined")
return Q.reject(new Error('Default Locale cannot be mapped to a store locale.'));
return Q.reject(new Error('Default Locale cannot be mapped to a store locale.'));

var toolName = 'makepri.exe';
return getWindowsKitPath(toolName)
Expand All @@ -215,6 +217,29 @@ function makePriConfig(priConfigFilePath, extManifest) {
});
}

function copyPriConfigTemplate(priConfigFilePath, extManifest) {
if (!extManifest.hasOwnProperty("default_locale"))
return Q.reject(new Error('No defualt_local in the extension manifest: CopyPriConfigTemplate failed'));

var priConfigTemplatePath = path.join(__dirname, 'assets', 'priconfig-template.xml');

return Q.nfcall(fs.readFile, priConfigTemplatePath).then(function (data) {
var defaultLocale = mapLocalesFromI18nToUWP(extManifest.default_locale);
var rawPriConfig = data.toString();

return rawPriConfig
.replace(/{default_locale}/g, defaultLocale);
})
.catch(function (err) {
return Q.reject(new CustomError('Could not read the priconfig template', err));
})
.then(function (priConfigText) {
return Q.nfcall(fs.writeFile, priConfigFilePath, priConfigText).catch(function (err) {
return Q.reject(new CustomError('Could not write the priconfig file', err));
});
})
}

function makePriFiles(manifestDir, extManifest) {
if (os.platform() !== 'win32') {
return Q.reject(new Error('Cannot generate a Windows Store package in the current platform.'));
Expand Down Expand Up @@ -252,5 +277,6 @@ module.exports = {
localizeAppxManifest: localizeAppxManifest,
createResJsonFiles: createResJsonFiles,
makePriConfig: makePriConfig,
copyPriConfigTemplate: copyPriConfigTemplate,
makePriFiles: makePriFiles
};
8 changes: 7 additions & 1 deletion lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function Platform (packageName, platforms) {
.then(function() {
self.info('Testing to see if localization is needed...');
shouldLocalize = localize.shouldLocalize(extManifestInfo.content);
if (extensionLocalesList.count > 0 && !shouldLocalize) {
self.warn('Localized resources exist but no we cannot localize this extension for Windows. In the manifest.json ensure default_locale is set and that either the name or description fields are pointing to localized resouces!');
}
})
// Create Localized Resources folder
.then(function () {
Expand All @@ -141,7 +144,10 @@ function Platform (packageName, platforms) {
.then(function () {
if (shouldLocalize) {
self.info('Creating the localization priconfig.xml file...');
localize.makePriConfig(path.join(manifestDir, "priconfig.xml"), extManifestInfo.content);

localize.copyPriConfigTemplate(path.join(manifestDir, "priconfig.xml"), extManifestInfo.content);

//localize.makePriConfig(path.join(manifestDir, "priconfig.xml"), extManifestInfo.content);
}
})
// write generation info (telemetry)
Expand Down
Loading

0 comments on commit 3aedf93

Please sign in to comment.