Skip to content

Commit 95ed8ad

Browse files
committed
translate fully
1 parent 55c40c9 commit 95ed8ad

File tree

16 files changed

+2889
-28
lines changed

16 files changed

+2889
-28
lines changed

lang/en_US.json

Lines changed: 1237 additions & 0 deletions
Large diffs are not rendered by default.

lang/ru_RU.json

Lines changed: 1342 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

src/lib/assets/lang-messages.ts

Lines changed: 8 additions & 0 deletions
Large diffs are not rendered by default.

src/lib/extensions/player.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const ScreenDisplaySymbol = Symbol('screen_display')
150150

151151
expand(Player.prototype, {
152152
get lang() {
153-
return Language.ru_RU
153+
return Language.en_US
154154
},
155155

156156
isSimulated() {

src/lib/form/chest.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { MinecraftItemTypes, MinecraftPotionLiquidTypes } from '@minecraft/vanil
55
import { Items, totalCustomItems } from 'lib/assets/custom-items'
66
import { textureData } from 'lib/assets/texture-data'
77
import { translateTypeId } from 'lib/i18n/lang'
8-
import { Message } from 'lib/i18n/message'
98
import { addNamespace, inspect, isKeyof, util, wrapLore } from 'lib/util'
109
import { typeIdToDataId, typeIdToID } from '../assets/chest-ui-type-ids'
1110
import { BUTTON, showForm } from './utils'
@@ -113,7 +112,7 @@ export class ChestForm {
113112
constructor(sizeType: keyof typeof SIZES = 'small') {
114113
const [sizeName, size] = SIZES[sizeType]
115114

116-
this.titleText = sizeName
115+
this.titleText = sizeName + '§0'
117116

118117
for (let i = 0; i < size; i++) this.buttons.push({ text: '', icon: undefined })
119118
}

src/lib/i18n/message.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { RawMessage, RawText } from '@minecraft/server'
22
import { defaultLang, Language } from 'lib/assets/lang'
33
import { Text, textUnitColorize } from './text'
4-
type I18nMessages = Record<string, Record<string, readonly string[]>>
4+
type I18nMessages = Record<string, Record<string, string | readonly string[]>>
55

66
const extractedMessageIdsToLangTokes: Record<string, string> = {}
7+
78
const extractedCompiledMessages: I18nMessages = {}
89

910
export type RawTextArg = string | RawText | Message | undefined | null
@@ -42,9 +43,9 @@ export class Message {
4243
}
4344

4445
color(c: Text.Colors | Pick<Text.Static<unknown>, 'currentColors'>) {
45-
if (this.postfixes.length) {
46-
console.warn(`Color modificator for message ${this.id} will not be applied for postfixes ${this.postfixes}`)
47-
}
46+
// if (this.postfixes.length) {
47+
// console.warn(`Color modificator for message ${this.id} will not be applied for postfixes ${this.postfixes}`)
48+
// }
4849

4950
this.colors = 'currentColors' in c ? c.currentColors : c
5051
for (const arg of this.args) {
@@ -122,9 +123,10 @@ export class Message {
122123

123124
export class I18nMessage extends Message {
124125
toString(language: Language): string {
126+
const translated = extractedCompiledMessages[language]?.[this.id]
125127
return Message.string(
126128
language,
127-
extractedCompiledMessages[language]?.[this.id] ?? this.template,
129+
translated ? (Array.isArray(translated) ? translated : [translated]) : this.template,
128130
this.args,
129131
this.colors,
130132
this.postfixes,

src/lib/i18n/text.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ describe('i18n', () => {
1818
expect(i18n`Some string with ${i18n.time(3000)} and`.size(30).toString(Language.en_US)).toMatchInlineSnapshot(
1919
`"§7Some string with §f3 seconds§7 and§7 §7(§630§7)"`,
2020
)
21+
22+
expect(i18n`Гробовщику посвящается`.toString(Language.en_US)).toMatchInlineSnapshot(`"For Gravestoner"`)
23+
24+
expect(i18n`Вы были выгнаны из клана игроком '${1}'. Причина: ${2}`.toString(Language.en_US)).toMatchInlineSnapshot(
25+
`"§7You were kicked from the clan by player '§61§7'. Reason: §62§7"`,
26+
)
2127
})
2228
})
2329

@@ -27,6 +33,10 @@ describe('text', () => {
2733
`"§7Some string §fthat colors§7 properly §65§7 times"`,
2834
)
2935
expect(i18n`Some string with ${player}`).toMatchInlineSnapshot(`"§7Some string with §fTest player name§7"`)
36+
37+
expect(i18n`Some string ${'§lthat colors'} properly ${5} times`).toMatchInlineSnapshot(
38+
`"§7Some string §f§lthat colors§7 properly §65§7 times"`,
39+
)
3040
})
3141

3242
it('should create nested text', () => {

src/lib/i18n/text.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export function textUnitColorize(
184184
): string {
185185
switch (typeof v) {
186186
case 'string':
187+
if (v.includes('§l')) return unit + v + '§r'
187188
return unit + v
188189
case 'undefined':
189190
return ''

src/lib/load/watchdog.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ declare global {
77

88
globalThis.loaded = Date.now()
99

10+
//@ts-expect-error Define global
11+
globalThis.Intl = {}
12+
1013
const reasons: Record<WatchdogTerminateReason, string> = {
1114
Hang: 'Скрипт завис',
1215
StackOverflow: 'Стэк переполнен',

0 commit comments

Comments
 (0)