Skip to content

Commit

Permalink
✨ Add translation_key mcdoc attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Dec 14, 2024
1 parent 1bfd90e commit af28eac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/symbol/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export const AssetsMiscCategories = Object.freeze(
[
'texture_slot',
'shader_target',
'translation_key',
] as const,
)
export type AssetsMiscCategory = (typeof AssetsMiscCategories)[number]
Expand Down
21 changes: 21 additions & 0 deletions packages/java-edition/src/json/mcdocAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const textureSlotValidator = validator.alternatives<TextureSlotConfig>(
() => ({ kind: 'value' }),
)

const translationKeyValidator = validator.alternatives(
validator.tree({
definition: validator.boolean,
}),
() => ({ definition: false }),
)

export function registerMcdocAttributes(meta: core.MetaRegistry) {
mcdoc.runtime.registerAttribute(meta, 'criterion', criterionValidator, {
stringParser: (config, _, ctx) => {
Expand Down Expand Up @@ -62,4 +69,18 @@ export function registerMcdocAttributes(meta: core.MetaRegistry) {
} satisfies TextureSlotNode
},
})
mcdoc.runtime.registerAttribute(meta, 'translation_key', translationKeyValidator, {
stringParser: (config, _, ctx) => {
return core.symbol({
category: 'translation_key',
usageType: config.definition ? 'definition' : 'reference',
})
},
stringMocker: (config, _, ctx) => {
return core.SymbolNode.mock(ctx.offset, {
category: 'translation_key',
usageType: config.definition ? 'definition' : 'reference',
})
},
})
}

0 comments on commit af28eac

Please sign in to comment.