Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide translate rank card #203

Merged
merged 5 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/docs/src/pages/guide/[topic]/_data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const pages = [
displayName: "Rank Card",
component: lazy(() => import("../_guides/Examples/rank-card.md")),
},
{
name: "cards-translation.md",
displayName: "Cards Translation",
component: lazy(() => import("../_guides/Examples/cards-translation.md")),
},
],
},
{
Expand Down
18 changes: 18 additions & 0 deletions apps/docs/src/pages/guide/_guides/Examples/cards-translation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Cards Translation

The `setTextStyles` method is used to customize the text styles for different elements in a rank card or leaderboard. This method allows for the modification of default labels for level, experience points (XP), and rank display.

## Usage

For Rank Card or Leaderboard :
```ts
const rankCard = new RankCardBuilder()
.setTextStyles({
level: 'NIVEAU :', // Custom text for the level
xp: 'EXP :', // Custom text for the experience points
rank: 'CLASSEMENT :' // Custom text for the rank
})
```

# Output
![xp-card](https://raw.githubusercontent.com/neplextech/canvacord/main/packages/canvacord/test/normal/cardTranslated.svg)
1 change: 1 addition & 0 deletions packages/canvacord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test": "vitest",
"coverage": "vitest --coverage",
"test:main": "tsx ./test/index.ts",
"test:translation": "tsx ./test/cards-translation.ts",
"test:lb": "tsx ./test/leaderboard.ts",
"test:jsx": "tsx ./test/jsxTest.tsx",
"test:demo": "tsx ./test/demo.tsx",
Expand Down
42 changes: 42 additions & 0 deletions packages/canvacord/test/cards-translation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { RankCardBuilder, Font, BuiltInGraphemeProvider } from "../src";
import { writeFileSync } from "fs";
import { RankCardUserStatus } from "../src/components/rank-card/NeoClassicalCard";

Font.loadDefault();

async function main() {
const card = new RankCardBuilder()
.setDisplayName("Wumpus 😍")
.setUsername("@wumpus")
.setAvatar("https://cdn.discordapp.com/embed/avatars/0.png?size=256")
.setCurrentXP(300)
.setRequiredXP(600)
.setProgressCalculator(() => {
return Math.floor(Math.random() * 100);
})
.setLevel(2)
.setRank(5)
.setOverlay(90)
.setBackground("#23272a")
.setTextStyles({level: 'NIVEAU :', xp: 'EXP :', rank: 'CLASSEMENT :'})
.setStatus(RankCardUserStatus.Online)
.setGraphemeProvider(BuiltInGraphemeProvider.FluentEmojiFlat);

card
.build({
format: "png",
})
.then((data) => {
writeFileSync(`${__dirname}/normal/cardTranslated.png`, data);
});

card
.build({
format: "svg",
})
.then((data) => {
writeFileSync(`${__dirname}/normal/cardTranslated.svg`, data);
});
}

main();
Loading