forked from vitmalina/w2ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New gulp task ``gulp locales`` - also part of ``gulp default`` - updates all locale files based on the master file w2locale.js Moved locale related settings from w2utils.js to w2locale.js - this is now basically the master English (en-us) translations file. Added current date string to gulp's w2ui header. Changed line breaks in locale file from CRLF to LF. Added missing German translations.
- Loading branch information
Showing
6 changed files
with
200 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
/* eslint-env node */ | ||
const gulp = require('gulp') | ||
const { exec } = require('child_process') | ||
const header = require('gulp-header') | ||
const iconfont = require('gulp-iconfont') | ||
const less = require('gulp-less') | ||
const cleanCSS = require('gulp-clean-css') | ||
const uglify = require('gulp-uglify') | ||
const concat = require('gulp-concat') | ||
const rename = require('gulp-rename') | ||
const babel = require('gulp-babel') | ||
const replace = require('gulp-replace') | ||
const del = require('del') | ||
// const babel = require('gulp-babel') | ||
// const { exec } = require('child_process') | ||
const comments = { | ||
w2ui : '/* w2ui 2.0.x (nightly) (c) http://w2ui.com, [email protected] */\n' | ||
w2ui : '/* w2ui 2.0.x (nightly) ('+ (new Date()).toLocaleDateString('en-us') +') (c) http://w2ui.com, [email protected] */\n' | ||
} | ||
|
||
let tasks = { | ||
|
@@ -48,6 +49,7 @@ let tasks = { | |
return gulp | ||
.src([ | ||
'src/w2event.js', // order of files is important | ||
'src/w2locale.js', | ||
'src/w2utils.js', | ||
'src/w2grid.js', | ||
'src/w2layout.js', | ||
|
@@ -67,6 +69,7 @@ let tasks = { | |
build(cb) { | ||
gulp.src([ | ||
'src/w2event.js', // order of files is important | ||
'src/w2locale.js', | ||
'src/w2utils.js', | ||
'src/w2grid.js', | ||
'src/w2layout.js', | ||
|
@@ -79,7 +82,7 @@ let tasks = { | |
'src/w2compat.js' // must be last | ||
]) | ||
.pipe(concat('w2ui.js')) | ||
.pipe(replace(/^import.*'$\n|^export.*}$\n/gm, '')) | ||
.pipe(replace(/^(import.*'|export.*}|module\.exports.*})$\n/gm, '')) | ||
.pipe(replace('\n\n', '\n')) | ||
// .pipe(babel()) | ||
.pipe(header(comments.w2ui)) | ||
|
@@ -137,7 +140,7 @@ let tasks = { | |
<h1 style="font-family: arial; padding-left: 15px;">w2ui-font $count</h1> | ||
` | ||
let json = [] | ||
let prom = gulp.src(['src/less/icons/svg/*.svg']) | ||
gulp.src(['src/less/icons/svg/*.svg']) | ||
.pipe(iconfont({ | ||
startUnicode: 65, | ||
fontName: 'w2ui-font', | ||
|
@@ -182,12 +185,61 @@ let tasks = { | |
gulp.watch(['src/**/*.js'], tasks.pack) // only packs dist/w2ui.js | ||
gulp.watch(['src/less/**/*.less'], tasks.less) | ||
gulp.watch(['src/less/icons/svg/*.svg'], tasks.icons) | ||
} | ||
}, | ||
|
||
locales(cb) { | ||
const fs = require('fs') | ||
const path = require('path') | ||
const isPrimitive = obj => obj === null || [ 'string', 'number', 'boolean' ].includes( typeof obj ) | ||
const isArrayOfPrimitive = obj => Array.isArray( obj ) && obj.every( isPrimitive ) | ||
const format = arr => | ||
`^^^[ ${ | ||
arr.map( val => JSON.stringify( val ) ).join( ', ' ) | ||
} ]` | ||
const replacer = ( key, value ) => isArrayOfPrimitive( value ) ? format( value ) : value | ||
const expand = str => str.replace( | ||
/(?:"\^\^\^)(\[ .* \])(?:\")/g, ( match, a ) => | ||
a.replace( /\\"/g, '"' ) | ||
) | ||
const stringify = (obj, space=4) => expand( JSON.stringify( obj, replacer, space ) ) | ||
function process_obj(m, o) { | ||
Object.keys(o).forEach(k => { | ||
if(typeof m[k] === 'undefined') delete o[k] | ||
}) | ||
for (const [k, v] of Object.entries(m)) { | ||
if(typeof o[k] === 'undefined') o[k] = v | ||
if(typeof v === 'object' && Object.keys(o[k]).length) o[k] = process_obj(v, o[k]) | ||
} | ||
return Object.assign(m, o) | ||
} | ||
function process_locales() { | ||
const master = require('./src/w2locale.cjs').w2locale | ||
const dir_locales = './src/locale' | ||
fs.readdir(dir_locales, (err, files) => { | ||
files.forEach(file => { | ||
let m = JSON.parse(JSON.stringify(master)) | ||
let filepath = path.join(dir_locales, file) | ||
let o = JSON.parse( fs.readFileSync(filepath) ) | ||
fs.writeFileSync(filepath, stringify(process_obj(m, o)) + '\n') | ||
}) | ||
}) | ||
} | ||
gulp.src(['src/w2locale.js']) | ||
.pipe(replace(/^export {/gm, 'module.exports = {')) | ||
.pipe(concat('w2locale.cjs')) | ||
.pipe(gulp.dest('src/')) | ||
.on('end', () => { | ||
process_locales() | ||
del('./src/w2locale.cjs') | ||
cb() | ||
}) | ||
}, | ||
} | ||
|
||
exports.default = gulp.series(tasks.clean, tasks.less, tasks.build) | ||
exports.default = gulp.series(tasks.clean, tasks.less, tasks.locales, tasks.build) | ||
exports.build = tasks.build | ||
exports.dev = tasks.watch | ||
exports.clean = tasks.clean | ||
exports.less = gulp.series(tasks.clean, tasks.less) | ||
exports.icons = gulp.series(tasks.icons, tasks.less) | ||
exports.locales = tasks.locales |
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
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,119 @@ | ||
/************************************************************************ | ||
* Part of w2ui 2.0 library | ||
* These are the master locale settings that will be used by w2utils | ||
************************************************************************/ | ||
|
||
const w2locale = { | ||
'locale' : 'en-us', | ||
'dateFormat' : 'm/d/yyyy', | ||
'timeFormat' : 'hh:mi pm', | ||
'datetimeFormat' : 'm/d/yyyy|hh:mi pm', | ||
'currencyPrefix' : '$', | ||
'currencySuffix' : '', | ||
'currencyPrecision' : 2, | ||
'groupSymbol' : ',', // aka "thousands separator" | ||
'decimalSymbol' : '.', | ||
'shortmonths' : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
'fullmonths' : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], | ||
'shortdays' : ['M', 'T', 'W', 'T', 'F', 'S', 'S'], | ||
'fulldays' : ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], | ||
'weekStarts' : 'M', // can be "M" for Monday or "S" for Sunday | ||
'phrases' : { // keep these up-to-date and in sorted order | ||
'${count} letters or more...': '${count} letters or more...', | ||
'Add new record': 'Add new record', | ||
'Add New': 'Add New', | ||
'Advanced Search': 'Advanced Search', | ||
'after': 'after', | ||
'AJAX error. See console for more details.': 'AJAX error. See console for more details.', | ||
'All Fields': 'All Fields', | ||
'All': 'All', | ||
'Any': 'Any', | ||
'Are you sure you want to delete ${count} ${records}?': 'Are you sure you want to delete ${count} ${records}?', | ||
'Attach files by dragging and dropping or Click to Select': 'Attach files by dragging and dropping or Click to Select', | ||
'before': 'before', | ||
'begins with': 'begins with', | ||
'begins': 'begins', | ||
'between': 'between', | ||
'buffered': 'buffered', | ||
'Cancel': 'Cancel', | ||
'Close': 'Close', | ||
'Column': 'Column', | ||
'Confirmation': 'Confirmation', | ||
'contains': 'contains', | ||
'Copied': 'Copied', | ||
'Copy to clipboard': 'Copy to clipboard', | ||
'Current Date & Time': 'Current Date & Time', | ||
'Delete selected records': 'Delete selected records', | ||
'Delete': 'Delete', | ||
'Do you want to delete search item "${item}"?': 'Do you want to delete search item "${item}"?', | ||
'Edit selected record': 'Edit selected record', | ||
'Edit': 'Edit', | ||
'Empty list': 'Empty list', | ||
'ends with': 'ends with', | ||
'ends': 'ends', | ||
'Field should be at least ${count} characters.': 'Field should be at least ${count} characters.', | ||
'Hide': 'Hide', | ||
'in': 'in', | ||
'is not': 'is not', | ||
'is': 'is', | ||
'less than': 'less than', | ||
'Line #': 'Line #', | ||
'Load ${count} more...': 'Load ${count} more...', | ||
'Loading...': 'Loading...', | ||
'Maximum number of files is ${count}': 'Maximum number of files is ${count}', | ||
'Maximum total size is ${count}': 'Maximum total size is ${count}', | ||
'Modified': 'Modified', | ||
'more than': 'more than', | ||
'Multiple Fields': 'Multiple Fields', | ||
'Name': 'Name', | ||
'No items found': 'No items found', | ||
'No matches': 'No matches', | ||
'No': 'No', | ||
'none': 'none', | ||
'Not a float': 'Not a float', | ||
'Not a hex number': 'Not a hex number', | ||
'Not a valid date': 'Not a valid date', | ||
'Not a valid email': 'Not a valid email', | ||
'Not alpha-numeric': 'Not alpha-numeric', | ||
'Not an integer': 'Not an integer', | ||
'Not in money format': 'Not in money format', | ||
'not in': 'not in', | ||
'Notification': 'Notification', | ||
'of': 'of', | ||
'Ok': 'Ok', | ||
'Record ID': 'Record ID', | ||
'record': 'record', | ||
'records': 'records', | ||
'Refreshing...': 'Refreshing...', | ||
'Reload data in the list': 'Reload data in the list', | ||
'Remove': 'Remove', | ||
'Request aborted.': 'Request aborted.', | ||
'Required field': 'Required field', | ||
'Reset': 'Reset', | ||
'Restore Default State': 'Restore Default State', | ||
'Returned data is not in valid JSON format.': 'Returned data is not in valid JSON format.', | ||
'Save changed records': 'Save changed records', | ||
'Save Grid State': 'Save Grid State', | ||
'Save': 'Save', | ||
'Saved Searches': 'Saved Searches', | ||
'Saving...': 'Saving...', | ||
'Search took ${count} seconds': 'Search took ${count} seconds', | ||
'Search': 'Search', | ||
'Select Hour': 'Select Hour', | ||
'Select Minute': 'Select Minute', | ||
'selected': 'selected', | ||
'Server Response ${count} seconds': 'Server Response ${count} seconds', | ||
'Show/hide columns': 'Show/hide columns', | ||
'Show': 'Show', | ||
'Size': 'Size', | ||
'Skip': 'Skip', | ||
'Sorting took ${count} seconds': 'Sorting took ${count} seconds', | ||
'Type to search...': 'Type to search...', | ||
'Type': 'Type', | ||
'Yes': 'Yes', | ||
'Yesterday': 'Yesterday', | ||
'Your remote data source record count has changed, reloading from the first record.': 'Your remote data source record count has changed, reloading from the first record.' | ||
} | ||
} | ||
|
||
export { w2locale } |
Oops, something went wrong.