Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nfkit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
nfkit
Commits
f0f42bd7
Commit
f0f42bd7
authored
Feb 08, 2026
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i18n support next with args
parent
765dfff5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
22 deletions
+49
-22
src/i18n/i18n.ts
src/i18n/i18n.ts
+37
-21
src/i18n/types.ts
src/i18n/types.ts
+12
-1
No files found.
src/i18n/i18n.ts
View file @
f0f42bd7
import
{
MiddlewareDispatcher
}
from
'
../middleware-dispatcher/middleware-dispatcher
'
;
import
{
parseI18n
}
from
'
../utility/parse-i18n
'
;
import
{
parseI18n
}
from
'
../utility/parse-i18n
'
;
import
{
I18nMiddleware
,
I18nOptions
}
from
'
./types
'
;
import
{
I18nMiddleware
,
I18nMiddlewareFunc
,
I18nMiddlewareNext
,
I18nOptions
,
}
from
'
./types
'
;
import
{
patchStringInObject
}
from
'
../patch-string-in-object
'
;
import
{
patchStringInObject
}
from
'
../patch-string-in-object
'
;
import
{
DynamicMiddlewareDispatcher
}
from
'
../middleware-dispatcher
'
;
class
I18nMiddlewareDispatcher
<
Ex
extends
any
[],
>
extends
DynamicMiddlewareDispatcher
<
I18nMiddlewareFunc
<
Ex
>>
{
constructor
()
{
super
({
acceptResult
:
(
res
)
=>
res
!=
null
,
errorHandler
:
(
e
)
=>
{
throw
e
;
},
});
}
middlewares
:
I18nMiddleware
<
Ex
>
[]
=
[];
async
buildMiddlewares
()
{
return
this
.
middlewares
.
map
(
(
mw
)
=>
(
locale
:
string
,
text
:
string
,
...
args
:
any
[])
=>
{
const
ex
=
args
.
slice
(
0
,
-
1
)
as
Ex
;
const
next
=
args
[
args
.
length
-
1
]
as
I18nMiddlewareNext
<
Ex
>
;
return
mw
(
locale
,
text
,
next
,
...
ex
);
},
);
}
}
export
class
I18n
<
Ex
extends
any
[]
=
[]
>
{
export
class
I18n
<
Ex
extends
any
[]
=
[]
>
{
constructor
(
private
options
:
I18nOptions
)
{}
constructor
(
private
options
:
I18nOptions
)
{}
...
@@ -9,35 +40,20 @@ export class I18n<Ex extends any[] = []> {
...
@@ -9,35 +40,20 @@ export class I18n<Ex extends any[] = []> {
locales
=
new
Set
(
this
.
options
.
locales
);
locales
=
new
Set
(
this
.
options
.
locales
);
defaultLocale
=
this
.
options
.
defaultLocale
??
this
.
options
.
locales
[
0
];
defaultLocale
=
this
.
options
.
defaultLocale
??
this
.
options
.
locales
[
0
];
private
mw
=
new
MiddlewareDispatcher
<
private
mw
=
new
I18nMiddlewareDispatcher
();
(
locale
:
string
,
text
:
string
,
...
ex
:
Ex
)
=>
string
|
undefined
>
({
acceptResult
:
(
res
)
=>
res
!=
null
,
errorHandler
:
(
e
)
=>
{
throw
e
;
},
});
private
shadowMiddlewares
:
I18nMiddleware
<
Ex
>
[]
=
[];
middleware
(
mw
:
I18nMiddleware
<
Ex
>
,
prior
=
false
)
{
middleware
(
mw
:
I18nMiddleware
<
Ex
>
,
prior
=
false
)
{
this
.
mw
.
middleware
((
locale
,
text
,
...
args
)
=>
{
const
ex
=
args
.
slice
(
0
,
-
1
)
as
Ex
;
const
next
=
args
[
args
.
length
-
1
]
as
()
=>
Promise
<
string
|
undefined
>
;
return
mw
(
locale
,
text
,
next
,
...
ex
);
},
prior
);
if
(
prior
)
{
if
(
prior
)
{
this
.
shadowM
iddlewares
.
unshift
(
mw
);
this
.
mw
.
m
iddlewares
.
unshift
(
mw
);
}
else
{
}
else
{
this
.
shadowM
iddlewares
.
push
(
mw
);
this
.
mw
.
m
iddlewares
.
push
(
mw
);
}
}
return
this
;
return
this
;
}
}
removeMiddleware
(
mw
:
I18nMiddleware
<
Ex
>
)
{
removeMiddleware
(
mw
:
I18nMiddleware
<
Ex
>
)
{
const
idx
=
this
.
shadowM
iddlewares
.
indexOf
(
mw
);
const
idx
=
this
.
mw
.
m
iddlewares
.
indexOf
(
mw
);
if
(
idx
>=
0
)
{
if
(
idx
>=
0
)
{
this
.
shadowMiddlewares
.
splice
(
idx
,
1
);
this
.
mw
.
middlewares
.
splice
(
idx
,
1
);
this
.
mw
.
middlewares
.
splice
(
idx
,
1
);
}
}
return
this
;
return
this
;
...
...
src/i18n/types.ts
View file @
f0f42bd7
import
{
MiddlewareNext
}
from
'
../middleware-dispatcher
'
;
import
{
Awaitable
}
from
'
../types
'
;
import
{
Awaitable
}
from
'
../types
'
;
export
type
I18nMiddlewareFunc
<
Ex
extends
any
[]
=
[]
>
=
(
locale
:
string
,
text
:
string
,
...
ex
:
Ex
)
=>
string
|
undefined
;
export
type
I18nMiddlewareNext
<
Ex
extends
any
[]
=
[]
>
=
MiddlewareNext
<
I18nMiddlewareFunc
<
Ex
>
>
;
export
type
I18nMiddleware
<
Ex
extends
any
[]
=
[]
>
=
(
export
type
I18nMiddleware
<
Ex
extends
any
[]
=
[]
>
=
(
locale
:
string
,
locale
:
string
,
text
:
string
,
text
:
string
,
next
:
()
=>
Promise
<
string
|
undefined
>
,
next
:
I18nMiddlewareNext
<
Ex
>
,
...
ex
:
Ex
...
ex
:
Ex
)
=>
Awaitable
<
string
|
undefined
>
;
)
=>
Awaitable
<
string
|
undefined
>
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment