Skip to content

Commit

Permalink
Merge pull request #687 from vexr/locale-handling-translations-leader…
Browse files Browse the repository at this point in the history
…board

Add locale handling in TranslationsLeaderboard
  • Loading branch information
EmilFattakhov authored Oct 15, 2024
2 parents de8ee87 + 8e88816 commit 4f2c69e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/components/TranslationLeaderboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@ const TranslationsLeaderboard = () => {
const fileToLoad = currentSelection === 'allTime' ? 'leaderboard.json' : 'leaderboard-monthly.json';
loadData(fileToLoad);
}, [currentSelection]);


// Function to format the word count according to the locale,
// using the locale from siteConfig if available, or falling back to the browser's default locale.
const formatWords = (wordsCount) => {
const numericCount = Number(wordsCount);
const locale = siteConfig.locale || navigator.language;
return numericCount.toLocaleString(locale);
};

// Filter users with Translated Words > 0
const filteredLeaderboardData = leaderboardData.filter(user => Number(user["Translated (Words)"]) > 0);

return (
<div className="leaderboard-container">
<div className="leaderboard-buttons">
<button onClick={() => setCurrentSelection('allTime')}>All Time</button>
<button onClick={() => setCurrentSelection('monthly')}>Monthly</button>
</div>
{leaderboardData.map((user, index) => (
{filteredLeaderboardData.map((user, index) => (
<div key={index} className="user-card">
<div className="avatar-container">
<span className="ranking">
Expand All @@ -44,7 +55,9 @@ const TranslationsLeaderboard = () => {
<span className="languages">{user.Languages || 'N/A'}</span>
</div>
</div>
<span className="translated-words">{user["Translated (Words)"]} words</span>
<span className="translated-words">
{formatWords(user["Translated (Words)"])} words
</span>
</div>
))}
</div>
Expand Down

0 comments on commit 4f2c69e

Please sign in to comment.