millas 0.2.12-beta-1 → 0.2.12-beta-2
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/package.json +1 -1
- package/src/admin/ActivityLog.js +153 -52
- package/src/admin/Admin.js +400 -167
- package/src/admin/AdminAuth.js +213 -98
- package/src/admin/FormGenerator.js +372 -0
- package/src/admin/HookRegistry.js +256 -0
- package/src/admin/QueryEngine.js +263 -0
- package/src/admin/ViewContext.js +309 -0
- package/src/admin/WidgetRegistry.js +406 -0
- package/src/admin/index.js +17 -0
- package/src/admin/resources/AdminResource.js +383 -97
- package/src/admin/static/admin.css +1341 -0
- package/src/admin/static/date-picker.css +157 -0
- package/src/admin/static/date-picker.js +316 -0
- package/src/admin/static/json-editor.css +649 -0
- package/src/admin/static/json-editor.js +1429 -0
- package/src/admin/static/ui.js +1044 -0
- package/src/admin/views/layouts/base.njk +65 -1013
- package/src/admin/views/pages/detail.njk +40 -16
- package/src/admin/views/pages/form.njk +47 -599
- package/src/admin/views/pages/list.njk +145 -62
- package/src/admin/views/partials/form-field.njk +53 -0
- package/src/admin/views/partials/form-footer.njk +28 -0
- package/src/admin/views/partials/form-readonly.njk +114 -0
- package/src/admin/views/partials/form-scripts.njk +476 -0
- package/src/admin/views/partials/form-widget.njk +296 -0
- package/src/admin/views/partials/json-dialog.njk +80 -0
- package/src/admin/views/partials/json-editor.njk +37 -0
- package/src/admin.zip +0 -0
- package/src/auth/Auth.js +18 -2
- package/src/auth/AuthUser.js +65 -44
- package/src/cli.js +3 -1
- package/src/commands/createsuperuser.js +254 -0
- package/src/commands/lang.js +589 -0
- package/src/commands/migrate.js +154 -81
- package/src/commands/serve.js +1 -0
- package/src/container/AppInitializer.js +65 -8
- package/src/container/MillasApp.js +10 -3
- package/src/container/MillasConfig.js +35 -6
- package/src/core/admin.js +5 -0
- package/src/core/db.js +2 -1
- package/src/core/foundation.js +1 -9
- package/src/core/lang.js +1 -0
- package/src/i18n/I18nServiceProvider.js +91 -0
- package/src/i18n/Translator.js +635 -0
- package/src/i18n/defaults.js +122 -0
- package/src/i18n/index.js +164 -0
- package/src/i18n/locales/en.js +55 -0
- package/src/i18n/locales/sw.js +48 -0
- package/src/logger/formatters/PrettyFormatter.js +101 -65
- package/src/migrations/system/0001_users.js +21 -0
- package/src/migrations/system/0002_admin_log.js +25 -0
- package/src/migrations/system/0003_sessions.js +23 -0
- package/src/orm/fields/index.js +210 -188
- package/src/orm/migration/DefaultValueParser.js +325 -0
- package/src/orm/migration/InteractiveResolver.js +191 -0
- package/src/orm/migration/Makemigrations.js +312 -0
- package/src/orm/migration/MigrationGraph.js +227 -0
- package/src/orm/migration/MigrationRunner.js +202 -108
- package/src/orm/migration/MigrationWriter.js +463 -0
- package/src/orm/migration/ModelInspector.js +143 -74
- package/src/orm/migration/ModelScanner.js +225 -0
- package/src/orm/migration/ProjectState.js +213 -0
- package/src/orm/migration/RenameDetector.js +175 -0
- package/src/orm/migration/SchemaBuilder.js +8 -81
- package/src/orm/migration/operations/base.js +57 -0
- package/src/orm/migration/operations/column.js +191 -0
- package/src/orm/migration/operations/fields.js +252 -0
- package/src/orm/migration/operations/index.js +55 -0
- package/src/orm/migration/operations/models.js +152 -0
- package/src/orm/migration/operations/registry.js +131 -0
- package/src/orm/migration/operations/special.js +51 -0
- package/src/orm/migration/utils.js +208 -0
- package/src/orm/model/Model.js +81 -13
- package/src/providers/AdminServiceProvider.js +66 -9
- package/src/providers/AuthServiceProvider.js +40 -5
- package/src/providers/CacheStorageServiceProvider.js +2 -2
- package/src/providers/DatabaseServiceProvider.js +3 -2
- package/src/providers/LogServiceProvider.js +4 -1
- package/src/providers/MailServiceProvider.js +1 -1
- package/src/providers/QueueServiceProvider.js +1 -1
- package/src/scaffold/templates.js +77 -21
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const ServiceProvider = require('../providers/ServiceProvider');
|
|
6
|
+
const Translator = require('./Translator');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* I18nServiceProvider
|
|
10
|
+
*
|
|
11
|
+
* Boots the translation system and registers the Trans singleton
|
|
12
|
+
* into the DI container.
|
|
13
|
+
*
|
|
14
|
+
* ── Setup in bootstrap/app.js ─────────────────────────────────────────────
|
|
15
|
+
*
|
|
16
|
+
* const { Millas } = require('millas');
|
|
17
|
+
* const I18nServiceProvider = require('millas/src/i18n/I18nServiceProvider');
|
|
18
|
+
*
|
|
19
|
+
* module.exports = Millas.config()
|
|
20
|
+
* .providers([I18nServiceProvider, AppServiceProvider])
|
|
21
|
+
* .create();
|
|
22
|
+
*
|
|
23
|
+
* ── config/app.js ─────────────────────────────────────────────────────────
|
|
24
|
+
*
|
|
25
|
+
* module.exports = {
|
|
26
|
+
* locale: 'en', // default locale
|
|
27
|
+
* fallback: 'en', // fallback when translation missing
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* ── lang/ directory ───────────────────────────────────────────────────────
|
|
31
|
+
*
|
|
32
|
+
* Place translation files at <basePath>/lang/:
|
|
33
|
+
*
|
|
34
|
+
* lang/
|
|
35
|
+
* en.js ← source language
|
|
36
|
+
* sw.js ← Swahili
|
|
37
|
+
* fr.js ← French
|
|
38
|
+
*
|
|
39
|
+
* ── Route-level locale switching ──────────────────────────────────────────
|
|
40
|
+
*
|
|
41
|
+
* Use the built-in middleware to auto-detect locale from requests:
|
|
42
|
+
*
|
|
43
|
+
* const { Trans } = require('millas/src/i18n');
|
|
44
|
+
* app.use(Trans.middleware());
|
|
45
|
+
*
|
|
46
|
+
* Or manually in a route:
|
|
47
|
+
* Trans.setLocale('sw');
|
|
48
|
+
*/
|
|
49
|
+
class I18nServiceProvider extends ServiceProvider {
|
|
50
|
+
|
|
51
|
+
register(container) {
|
|
52
|
+
// Register the Trans singleton into the DI container
|
|
53
|
+
const trans = require('./index').Trans;
|
|
54
|
+
container.instance('trans', trans);
|
|
55
|
+
container.instance('Trans', trans);
|
|
56
|
+
container.alias('i18n', 'trans');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async boot(container, app) {
|
|
60
|
+
const basePath = container.make('basePath') || process.cwd();
|
|
61
|
+
const trans = container.make('trans');
|
|
62
|
+
|
|
63
|
+
// Load config/app.js for locale settings
|
|
64
|
+
let locale = 'en';
|
|
65
|
+
let fallback = 'en';
|
|
66
|
+
let warnMissing = process.env.NODE_ENV !== 'production';
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const appConfig = require(path.join(basePath, 'config/app'));
|
|
70
|
+
if (appConfig.locale) locale = appConfig.locale;
|
|
71
|
+
if (appConfig.fallback) fallback = appConfig.fallback;
|
|
72
|
+
} catch { /* config/app.js not found or no locale keys */ }
|
|
73
|
+
|
|
74
|
+
// Lang path: <basePath>/lang/
|
|
75
|
+
const langPath = path.join(basePath, 'lang');
|
|
76
|
+
|
|
77
|
+
trans.configure({ locale, fallback, langPath, warnMissing });
|
|
78
|
+
|
|
79
|
+
// Log available locales on startup in debug mode
|
|
80
|
+
if (process.env.DEBUG || process.env.NODE_ENV === 'development') {
|
|
81
|
+
const available = trans.availableLocales();
|
|
82
|
+
if (available.length > 0 && !(available.length === 1 && available[0] === 'en')) {
|
|
83
|
+
process.stdout.write(
|
|
84
|
+
`[i18n] Locale: ${locale} | Fallback: ${fallback} | Available: ${available.join(', ')}\n`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = I18nServiceProvider;
|