Unverified Commit f1df1786 authored by Nathan Chu's avatar Nathan Chu Committed by GitHub
Browse files

feat: card locale translations (#509)



* Add Card Translations

* Add tests and documentation for `?lang` option

* Card Translations: update Italian

* Run Prettier

* Correct German Translations.

Co-authored-by: default avatarschmelto <30869493+schmelto@users.noreply.github.com>

* refactor: added i18n class to manage translation logic & improved code

* Make the new src/translations.js more concise

* Update translations.js

Co-authored-by: default avatarschmelto <30869493+schmelto@users.noreply.github.com>

* Revert 4175484d69289e4ee7283ab968b8e71c3c5d77df

* fix: overlap because of language length

Co-authored-by: default avatarlrusso96 <russo.1699981@studenti.uniroma1.it>
Co-authored-by: default avatarschmelto <30869493+schmelto@users.noreply.github.com>
Co-authored-by: default avatarAnurag <hazru.anurag@gmail.com>
parent 2707d074
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ const {
  parseArray,
  clampValue,
  CONSTANTS,
  isLocaleAvailable,
} = require("../src/common/utils");
const fetchStats = require("../src/fetchers/stats-fetcher");
const renderStatsCard = require("../src/cards/stats-card");
@@ -28,6 +29,7 @@ module.exports = async (req, res) => {
    theme,
    cache_seconds,
    custom_title,
    locale,
  } = req.query;
  let stats;

@@ -37,6 +39,10 @@ module.exports = async (req, res) => {
    return res.send(renderError("Something went wrong"));
  }

  if (locale && !isLocaleAvailable(locale)) {
    return res.send(renderError("Something went wrong", "Language not found"));
  }

  try {
    stats = await fetchStats(
      username,
@@ -67,6 +73,7 @@ module.exports = async (req, res) => {
        bg_color,
        theme,
        custom_title,
        locale: locale ? locale.toLowerCase() : null,
      }),
    );
  } catch (err) {
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ const {
  parseBoolean,
  clampValue,
  CONSTANTS,
  isLocaleAvailable,
} = require("../src/common/utils");
const fetchRepo = require("../src/fetchers/repo-fetcher");
const renderRepoCard = require("../src/cards/repo-card");
@@ -21,6 +22,7 @@ module.exports = async (req, res) => {
    theme,
    show_owner,
    cache_seconds,
    locale,
  } = req.query;

  let repoData;
@@ -31,6 +33,10 @@ module.exports = async (req, res) => {
    return res.send(renderError("Something went wrong"));
  }

  if (locale && !isLocaleAvailable(locale)) {
    return res.send(renderError("Something went wrong", "Language not found"));
  }

  try {
    repoData = await fetchRepo(username, repo);

@@ -64,6 +70,7 @@ module.exports = async (req, res) => {
        bg_color,
        theme,
        show_owner: parseBoolean(show_owner),
        locale: locale ? locale.toLowerCase() : null,
      }),
    );
  } catch (err) {
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ const {
  parseBoolean,
  parseArray,
  CONSTANTS,
  isLocaleAvailable,
} = require("../src/common/utils");
const fetchTopLanguages = require("../src/fetchers/top-languages-fetcher");
const renderTopLanguages = require("../src/cards/top-languages-card");
@@ -26,6 +27,7 @@ module.exports = async (req, res) => {
    langs_count,
    exclude_repo,
    custom_title,
    locale,
  } = req.query;
  let topLangs;

@@ -35,6 +37,10 @@ module.exports = async (req, res) => {
    return res.send(renderError("Something went wrong"));
  }

  if (locale && !isLocaleAvailable(locale)) {
    return res.send(renderError("Something went wrong", "Language not found"));
  }

  try {
    topLangs = await fetchTopLanguages(
      username,
@@ -62,6 +68,7 @@ module.exports = async (req, res) => {
        bg_color,
        theme,
        layout,
        locale: locale ? locale.toLowerCase() : null,
      }),
    );
  } catch (err) {
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ const {
  parseBoolean,
  clampValue,
  CONSTANTS,
  isLocaleAvailable,
} = require("../src/common/utils");
const { fetchLast7Days } = require("../src/fetchers/wakatime-fetcher");
const wakatimeCard = require("../src/cards/wakatime-card");
@@ -22,10 +23,15 @@ module.exports = async (req, res) => {
    hide_title,
    hide_progress,
    custom_title,
    locale,
  } = req.query;

  res.setHeader("Content-Type", "image/svg+xml");

  if (locale && !isLocaleAvailable(locale)) {
    return res.send(renderError("Something went wrong", "Language not found"));
  }

  try {
    const last7Days = await fetchLast7Days({ username });

@@ -53,6 +59,7 @@ module.exports = async (req, res) => {
        bg_color,
        theme,
        hide_progress,
        locale: locale ? locale.toLowerCase() : null,
      }),
    );
  } catch (err) {
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
- `hide_border` - Hides the card's border _(boolean)_
- `theme` - name of the theme, choose from [all available themes](./themes/README.md)
- `cache_seconds` - set the cache header manually _(min: 1800, max: 86400)_
- `lang` - set the language in the card _(e.g. cn, de, es, etc.)_

##### Gradient in bg_color

Loading