Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Extract i18n string into i18n/_defaults (base of translations) #4514

Merged
merged 21 commits into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"development": {
"plugins": [
"react-hot-loader/babel",
["react-intl", { "messagesDir": "./.build/i18n/" }]
[ "react-intl", { "messagesDir": "./.build/i18n/" } ]
]
},
"test": {
Expand Down
1 change: 1 addition & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"build:markdown": "babel-node ./scripts/build-rpc-markdown.js",
"build:json": "babel-node ./scripts/build-rpc-json.js",
"build:embed": "EMBED=1 node webpack/embed",
"build:i18n": "npm run clean && BABEL_ENV=development npm run build && babel-node ./scripts/build-i18n.js",
"ci:build": "npm run ci:build:lib && npm run ci:build:dll && npm run ci:build:app && npm run ci:build:embed",
"ci:build:app": "NODE_ENV=production webpack --config webpack/app",
"ci:build:lib": "NODE_ENV=production webpack --config webpack/libraries",
Expand Down
85 changes: 85 additions & 0 deletions js/scripts/build-i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import fs from 'fs';
import path from 'path';

import i18nstrings from '../.build/i18n/i18n/en.json';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is babel-node used only for these imports ? If it is, could use require I think...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const/let is supported, so only imports. I would prefer keeping the import just for code-base consistency. (Although there is a slight compiler indirection involved here)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind but it adds quite some work for not so much. All the other scripts are using standard Node syntax


const FILE_HEADER = '// Copyright 2015-2017 Parity Technologies (UK) Ltd.\n// This file is part of Parity.\n\n// Parity is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// Parity is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with Parity. If not, see <http://www.gnu.org/licenses/>.\n\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use template string here, would be more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually did have it that way around, will put it back. (Don't expect to edit it at all, but still more readable.)

const SECTION_HEADER = 'export default ';
const SECTION_FOOTER = ';\n';
const INDENT = ' ';
const I18NPATH = path.join(__dirname, '../src/i18n/_default');

// FIXME: Expanding it this way is probably not quite optimal, some would say hacky.
// However JSON.stringify (the sane solution) let us end up with both the keys
// and values with "'s which is not intended. We want keys without and values with `
// (Better idea welcome, at this point not critical since we control inputs)
function createExportString (section, indent) {
if (Object.prototype.toString.call(section) === '[object String]') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (typeof section === 'string')

return `\`${section}\``;
}

const keys = Object
.keys(section)
.sort()
.map((key) => {
return `${indent}${key}: ${createExportString(section[key], indent + INDENT)}`;
})
.join(',\n');

return `{\n${keys}\n${indent.substr(2)}}`;
}

const sections = {};

// create an object map of the actual inputs
Object.keys(i18nstrings).forEach((fullKey) => {
const defaultMessage = i18nstrings[fullKey].defaultMessage;
const keys = fullKey.split('.');
let outputs = sections;

keys.forEach((key, index) => {
if (index === keys.length - 1) {
outputs[key] = defaultMessage;
} else {
if (!outputs[key]) {
outputs[key] = {};
}

outputs = outputs[key];
}
});
});

// create the index.js file
const sectionKeys = Object.keys(sections).sort();
const exports = sectionKeys
.map((key) => {
return `export ${key} from './${key}';`;
})
.join('\n');

fs.writeFileSync(path.join(I18NPATH, 'index.js'), `${FILE_HEADER}${exports}\n`, 'utf8');

// create the individual section files
sectionKeys.forEach((key) => {
// const sectionText = JSON.stringify(sections[key], null, 2);
const sectionText = createExportString(sections[key], INDENT);

fs.writeFileSync(path.join(I18NPATH, `${key}.js`), `${FILE_HEADER}${SECTION_HEADER}${sectionText}${SECTION_FOOTER}`, 'utf8');
});
35 changes: 35 additions & 0 deletions js/src/i18n/_default/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
button: {
delete: `delete account`,
edit: `edit`,
password: `password`,
shapeshift: `shapeshift`,
transfer: `transfer`,
verify: `verify`
},
header: {
outgoingTransactions: `{count} outgoing transactions`,
uuid: `uuid: {uuid}`
},
title: `Account Management`,
transactions: {
poweredBy: `Transaction list powered by {etherscan}`,
title: `transactions`
}
};
21 changes: 21 additions & 0 deletions js/src/i18n/_default/accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
summary: {
minedBlock: `Mined at block #{blockNumber}`
}
};
37 changes: 37 additions & 0 deletions js/src/i18n/_default/addAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
button: {
add: `Save Address`,
close: `Cancel`
},
input: {
address: {
hint: `the network address for the entry`,
label: `network address`
},
description: {
hint: `an expanded description for the entry`,
label: `(optional) address description`
},
name: {
hint: `a descriptive name for the entry`,
label: `address name`
}
},
label: `add saved address`
};
60 changes: 60 additions & 0 deletions js/src/i18n/_default/addContract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
abi: {
hint: `the abi for the contract`,
label: `contract abi`
},
abiType: {
custom: {
description: `Contract created from custom ABI`,
label: `Custom Contract`
},
multisigWallet: {
description: `Ethereum Multisig contract {link}`,
label: `Multisig Wallet`,
link: `see contract code`
},
token: {
description: `A standard {erc20} token`,
erc20: `ERC 20`,
label: `Token`
}
},
address: {
hint: `the network address for the contract`,
label: `network address`
},
button: {
add: `Add Contract`,
cancel: `Cancel`,
next: `Next`,
prev: `Back`
},
description: {
hint: `an expanded description for the entry`,
label: `(optional) contract description`
},
name: {
hint: `a descriptive name for the contract`,
label: `contract name`
},
title: {
details: `enter contract details`,
type: `choose a contract type`
}
};
26 changes: 26 additions & 0 deletions js/src/i18n/_default/addressSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
fromEmail: `Verified using email {email}`,
fromRegistry: `{name} (from registry)`,
labels: {
accounts: `accounts`,
contacts: `contacts`,
contracts: `contracts`
},
noAccount: `No account matches this query...`
};
27 changes: 27 additions & 0 deletions js/src/i18n/_default/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
status: {
consensus: {
capable: `Capable`,
capableUntil: `Capable until #{blockNumber}`,
incapableSince: `Incapable since #{blockNumber}`,
unknown: `Unknown capability`
},
upgrade: `Upgrade`
}
};
26 changes: 26 additions & 0 deletions js/src/i18n/_default/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
connectingAPI: `Connecting to the Parity Secure API.`,
connectingNode: `Connecting to the Parity Node. If this informational message persists, please ensure that your Parity node is running and reachable on the network.`,
invalidToken: `invalid signer token`,
noConnection: `Unable to make a connection to the Parity Secure API. To update your secure token or to generate a new one, run {newToken} and supply the token below`,
token: {
hint: `a generated token from Parity`,
label: `secure token`
}
};
19 changes: 19 additions & 0 deletions js/src/i18n/_default/contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default {
minedBlock: `Mined at block #{blockNumber}`
};
Loading