Skip to content

Commit 9a464e7

Browse files
authored
Merge pull request #487 from devforth/next
Next
2 parents 0ce5ca3 + 8130cd9 commit 9a464e7

File tree

27 files changed

+297
-78
lines changed

27 files changed

+297
-78
lines changed

adminforth/commands/createApp/utils.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import Handlebars from 'handlebars';
1313
import { promisify } from 'util';
1414
import { getVersion } from '../cli.js';
1515

16+
import { URL } from 'url'
17+
import net from 'net'
18+
1619
const execAsync = promisify(exec);
1720

1821
function detectAdminforthVersion() {
@@ -159,6 +162,44 @@ function checkForExistingPackageJson(options) {
159162
}
160163
}
161164

165+
function checkIfDatabaseLocal(urlString) {
166+
if (urlString.startsWith('sqlite')) {
167+
return true;
168+
}
169+
try {
170+
const url = new URL(urlString)
171+
172+
const host = url.hostname
173+
174+
if (!host) return false
175+
176+
// localhost
177+
if (host === 'localhost') return true
178+
179+
// loopback ipv4
180+
if (host === '127.0.0.1') return true
181+
182+
// loopback ipv6
183+
if (host === '::1') return true
184+
185+
// private IP ranges
186+
if (net.isIP(host)) {
187+
if (
188+
host.startsWith('10.') ||
189+
host.startsWith('192.168.') ||
190+
host.match(/^172\.(1[6-9]|2\d|3[0-1])\./)
191+
) {
192+
return true
193+
}
194+
}
195+
196+
197+
return false
198+
} catch {
199+
return false
200+
}
201+
}
202+
162203
async function scaffoldProject(ctx, options, cwd) {
163204
const projectDir = path.join(cwd, options.appName);
164205
await fse.ensureDir(projectDir);
@@ -253,7 +294,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
253294
{
254295
src: '.env.local.hbs',
255296
dest: '.env.local',
256-
data: { dbUrl, prismaDbUrl },
297+
data: { dbUrl: checkIfDatabaseLocal(dbUrl) ? dbUrl : null, prismaDbUrl },
257298
},
258299
{
259300
src: '.env.prod.hbs',
@@ -269,8 +310,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
269310
// We'll write .env using the same content as .env.sample
270311
src: '.env.local.hbs',
271312
dest: '.env',
272-
data: {},
273-
empty: true,
313+
data: {dbUrl, prismaDbUrl},
274314
},
275315
{
276316
src: 'adminuser.ts.hbs',

adminforth/documentation/docs/tutorial/08-Plugins/02-TwoFactorsAuth.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,24 @@ Add the new resource to index.ts:
697697
...
698698
],
699699
```
700+
To use passkey you need to use Key-Value adapter. For example:
701+
```bash
702+
npm i @adminforth/key-value-adapter-ram
703+
```
704+
700705
701706
Now, update the settings of the Two-Factor Authentication plugin:
702707
703708
```ts tittle='./resources/adminuser.ts'
709+
710+
//diff-add
711+
import RamKeyValueAdapter from '@adminforth/key-value-adapter-ram'
712+
713+
...
714+
704715
plugins: [
705716
new TwoFactorsAuthPlugin ({
717+
keyValueAdapter: new RamKeyValueAdapter(),
706718
twoFaSecretFieldName: 'secret2fa',
707719
timeStepWindow: 1,
708720
//diff-add

adminforth/documentation/docs/tutorial/08-Plugins/04-RichEditor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,4 @@ new RichEditorPlugin({
263263
attachmentResourceIdFieldName: "resource_id",
264264
}
265265
})
266+
```

adminforth/documentation/docs/tutorial/08-Plugins/10-i18n.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,71 @@ import { admin } from '../index';
572572
}
573573
```
574574
575+
## Different scripts (writing systems) / regions / variants / dialects
576+
577+
### Scripts (Writing systems)
578+
579+
For some languages you may want translations in a specific, non-default script (or want the choice to be deterministic).
580+
581+
For example, Serbian (`sr`) is written in both Cyrillic and Latin scripts. If you use only `sr`, an LLM may pick a script inconsistently (or default to Cyrillic). To force a particular script, use `translateLangAsBCP47Code`:
582+
583+
```ts
584+
translateLangAsBCP47Code: { sr: 'sr-Latn' }
585+
```
586+
587+
Alternatively, you can or course use the script-tagged BCP47 code directly in `supportedLanguages`:
588+
589+
```diff
590+
--- supportedLanguages: ['en', 'sr']
591+
+++ supportedLanguages: ['en', 'sr-Latn']
592+
```
593+
594+
However, in this case `sr-Latn` becomes the language identifier everywhere. For example if you expose language codes to an external app (e.g., in URLs or subdomains), you may end up with URLs like `https://my.site/sr-Latn/my-page`, which is sometimes undesirable. You can work around this by remapping `sr-Latn ↔ sr` in the external system, but we generally recommend `translateLangAsBCP47Code` as the dedicated, internal way to keep a clean ISO 639-1 code while translating as a specific BCP47 tag.
595+
596+
If you want to support both scripts explicitly, include both in `supportedLanguages`:
597+
598+
```ts
599+
supportedLanguages: ['en', 'sr-Latn', 'sr-Cyrl']
600+
```
601+
602+
### Dialects and national standards
603+
604+
European Portuguese and Brazilian Portuguese differ, so it’s common to use BCP47 region subtags to distinguish them.
605+
606+
To support both:
607+
608+
```ts
609+
supportedLanguages: ['en', 'pt-BR', 'pt-PT']
610+
```
611+
612+
If you only want one version (e.g. Brazilian Portuguese) but still want to keep a clean `pt` code in your API/URLs, use `translateLangAsBCP47Code`:
613+
614+
```ts
615+
supportedLanguages: ['en', 'pt']
616+
translateLangAsBCP47Code: { pt: 'pt-BR' }
617+
```
618+
619+
LLM adapters generally understand the BCP47 tags you provide.
620+
621+
### Variants
622+
623+
More rarely, you may need a specific language variant. For example, British English typically uses standard BrE spelling, but the Oxford English Dictionary variant (OED) differs in some cases:
624+
625+
| Standard BrE | Oxford (OED) |
626+
| --- | --- |
627+
| colour | colour |
628+
| organise | organize |
629+
| realise | realize |
630+
631+
You can use `translateLangAsBCP47Code` to request a specific variant:
632+
633+
```ts
634+
supportedLanguages: ['en']
635+
translateLangAsBCP47Code: { en: 'en-GB-oed' }
636+
```
637+
638+
As any BCP47 tag it is also supported in `supportedLanguages` directly, but again this will make the full tag (e.g., `en-GB-oed`) appear in your API/URLs external systems unless you remap it externally.
639+
575640
## Translating external application
576641
577642
You can use this module not only to translate admin area of your application but also to translate other parts like SEO-facing or user-facing services.

adminforth/documentation/src/css/custom.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ pre code:has(.code-block-diff-remove-line) {
207207
.laptop .theme_switcher {
208208
position: absolute;
209209
cursor: pointer;
210-
top: 2.56vw;
211-
right: 5.28vw;
210+
top: 2.84vw;
211+
right: 5.98vw;
212212
width: 2vw;
213213
height: 2vw;
214214
font-size: 1.5vw;

adminforth/documentation/src/pages/index.module.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@
3232
}
3333

3434

35+
.card-demo {
36+
max-width: 500px;
37+
}
38+
39+
.cardsWrapper {
40+
display: grid;
41+
grid-template-columns: repeat(3, minmax(300px, 500px));
42+
gap: 4rem;
43+
justify-content: center;
44+
padding: 1rem;
45+
46+
@media (max-width: 1200px) {
47+
grid-template-columns: repeat(2, minmax(300px, 500px));
48+
}
49+
@media (max-width: 768px) {
50+
grid-template-columns: repeat(1, minmax(300px, 500px));
51+
}
52+
53+
}

adminforth/documentation/src/pages/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const images = [
4444
original: require('@site/static/img/previews/2fa_plugin.png').default,
4545
title: '2FA Plugin - secure your admin panel',
4646
link: '/docs/tutorial/Plugins/TwoFactorsAuth/',
47-
description: 'RFC 6238-Compliant TOTP-Based 2FA will add additional security layer to your admin panel'
47+
description: 'RFC 6238-Compliant TOTP-Based 2FA will add additional security layer to your admin panel. Also supports passkeys'
4848
},
4949
{
5050
original: require('@site/static/img/previews/dark.png').default,
@@ -105,7 +105,13 @@ const images = [
105105
title: 'AI Translation Plugin - translate your admin and External apps',
106106
link: '/docs/tutorial/Plugins/i18n/',
107107
description: 'Use LLMs to translate any external apps (Mobile, Nuxt, etc.) OR/AND admin panel with minimal effort. Any language supported'
108-
}
108+
},
109+
{
110+
original: require('@site/static/img/previews/bulk-ai-flow.png').default,
111+
title: 'Bulk AI Plugin - generate data for your resources',
112+
link: '/docs/tutorial/Plugins/bulk-ai-flow/',
113+
description: 'Use LLMs to fill records with generated data or images. For example, generate product descriptions based on product name and image or generate products images'
114+
},
109115
];
110116

111117

@@ -201,13 +207,7 @@ export default function Home(): JSX.Element {
201207
What it can do for you
202208
</Heading>
203209

204-
<div style={{
205-
display: 'flex',
206-
flexWrap: 'wrap',
207-
gap: '4rem',
208-
justifyContent: 'center',
209-
padding: '1rem',
210-
}}>
210+
<div className={styles.cardsWrapper}>
211211
{images.map((item, index) => (
212212
<div className="card-demo" key={`feature${index}`}>
213213
<div className="card shadow--md" style={{
-71.5 KB
Loading
-101 KB
Loading
-91.7 KB
Loading

0 commit comments

Comments
 (0)