Expanding Localization for GitHub Streak Stats with the New 't' Parameter

Enhancing Localization for GitHub Streak Stats

The FlavioKde/github-streak-stats-api project provides a service for generating beautiful SVG representations of GitHub streak statistics. These visual summaries are popular for showcasing developer consistency and contributions. To make these stats even more accessible and customizable for a global audience, we've introduced a new feature: an extended translation scope controlled by the t parameter.

The Need for Broader Localization

Previously, while some basic text elements in the generated SVG could be localized, the scope was limited. Developers and users often wished to display their streak stats in languages beyond the default or to customize specific labels and phrases more thoroughly. This limitation meant that while the core data was universal, its presentation could feel less personal or relevant to non-English speakers.

Introducing the 't' Parameter for Enhanced Translation

With the latest update, a new t parameter has been added to the renderStreakSvg function. This parameter allows users to specify an extended translation scope, effectively enabling more comprehensive localization for the text elements within the generated SVG.

By passing a JSON object or a string representing a translation key to the t parameter, developers can now dictate how various labels, descriptions, and metrics are presented. This significantly enhances the ability to tailor the output to specific languages or even unique phrasing requirements.

For example, to render a streak SVG with custom labels, one might structure the request as follows:

async function getLocalizedStreakStats(username, customTranslations) {
  const apiUrl = `https://github-streak-stats-api.example.com/api?user=${username}&t=${encodeURIComponent(JSON.stringify(customTranslations))}`;
  const response = await fetch(apiUrl);
  const svgContent = await response.text();
  console.log(svgContent);
}

const myTranslations = {
  "CURRENT_STREAK": "Active Run",
  "LONGEST_STREAK": "Personal Best",
  "TOTAL_CONTRIBUTIONS": "All Contributions"
};

getLocalizedStreakStats("octocat", myTranslations);

In this example, customTranslations would be a JavaScript object that maps specific internal keys (like "CURRENT_STREAK") to their desired localized strings. The API then uses these provided translations when generating the SVG, ensuring the output reflects the user's linguistic preferences.

Impact and Future Possibilities

This enhancement provides greater flexibility for users around the world, allowing them to truly own the presentation of their GitHub streak data. It simplifies the process of integrating these SVG stats into multi-lingual platforms and opens the door for community contributions to translation packs. The t parameter empowers developers to create a more inclusive and personalized experience for their users.

Actionable Takeaway

Explore the new t parameter for FlavioKde/github-streak-stats-api to customize your GitHub streak SVG outputs with tailored translations. Consult the project documentation (or experiment with JSON objects) to identify the available translation keys and start localizing your stats today.


Generated with Gitvlg.com

Expanding Localization for GitHub Streak Stats with the New 't' Parameter
Flavio A. D'Avirro

Flavio A. D'Avirro

Author

Share: