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

Opt in auto updates for translations #310

Open
2 of 3 tasks
tonyaellie opened this issue Oct 29, 2024 · 1 comment
Open
2 of 3 tasks

Opt in auto updates for translations #310

tonyaellie opened this issue Oct 29, 2024 · 1 comment
Assignees
Labels
⬆️ enhancement New feature or request

Comments

@tonyaellie
Copy link
Collaborator

What is the problem you are trying to solve with this feature?

Currently to update translations a full release has to be made, this means that it takes a relatively long time to get new translation changes.

What is the solution you are proposing?

An option to have homebox automatically check for updates to the translations and download them.

What alternatives have you considered?

Wait for releases.

Additional context

No response

Contributions

  • I have searched through existing issues and feature requests to see if my idea has already been proposed.
  • If this feature is accepted, I would be willing to help implement and maintain this feature.
  • If this feature is accepted, I'm willing to sponsor the development of this feature.
@tonyaellie tonyaellie added the ⬆️ enhancement New feature or request label Oct 29, 2024
@tonyaellie tonyaellie self-assigned this Oct 29, 2024
@tonyaellie
Copy link
Collaborator Author

Dynamically fetch translation files in messages

export default defineNuxtPlugin(async ({ vueApp }) => {
  async function checkDefaultLanguage() {
    let matched = null;
    const languages = Object.getOwnPropertyNames(await messages());
    const matching = navigator.languages.filter(lang => languages.some(l => l.toLowerCase() === lang.toLowerCase()));
    if (matching.length > 0) {
      matched = matching[0];
    }
    if (!matched) {
      languages.forEach(lang => {
        const languagePartials = navigator.language.split("-")[0];
        if (lang.toLowerCase() === languagePartials) {
          matched = lang;
        }
      });
    }
    return matched;
  }
  const preferences = useViewPreferences();
  const i18n = createI18n({
    fallbackLocale: "en",
    globalInjection: true,
    legacy: false,
    locale: preferences.value.language || await checkDefaultLanguage() || "en",
    messageCompiler,
    messages: await messages(),
  });
  vueApp.use(i18n);
});

export const messages = async () => {
  const messages: Record<string, any> = {};
  // const modules = import.meta.glob("~//locales/**.json", { eager: true });
  // for (const path in modules) {
  //   const key = path.slice(9, -5);
  //   messages[key] = modules[path];
  // }
  console.log('Fetching translations...');
  const en = await (await fetch('http://localhost:3001/en.json')).json();
  console.log('Fetched translations.');
  messages['en'] = en;
  return messages;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬆️ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant