question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: Support loading from alternate path

See original GitHub issue

At runtime, we should support the use case of loading a file other than /index.html. For example: __app.html or en-US/index.html. This could also be a configuration option, but we should be able to override it at runtime to allow for use cases such as this: https://github.com/ionic-team/capacitor/discussions/3905

see https://github.com/ionic-team/capacitor/pull/3405 depends on https://github.com/ionic-team/capacitor/issues/3913

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rdlabocommented, Oct 11, 2022

Thanks @UltraCakeBakery for your feedback.

My idea is to pack capacitor with all language folders produced by ng build and add an index.html file on the root folder. The root index file has just to check the device’s preferred language and redirects to the correct folder.

What do you think?

This work well. I prepared this html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script type="text/javascript">
      // If true, you should set localStorage[storageKey] in your app.
      const saveLocale = true;
      const storageKey = 'locale';
      const defaultLocale = 'ja';
      const localeMap = {
        ja: ['ja', 'ja-JP'],
        'en-us': ['en', 'en-US'],
      };

      // Method
      const getBrowserLanguage = (navigator) => {
        if (!navigator) return null;
        if (navigator.languages && navigator.languages.length > 0) return navigator.languages[0];
        if (navigator.userLanguage) return navigator.userLanguage;
        return navigator.language;
      };
      const getToRoute = (locale) => {
        return Object.keys(localeMap).find((key) => {
          if (localeMap[key].map((l) => l.toLowerCase()).includes(locale)) return true;
        });
      };

      // Run redirect
      (() => {
        let locale = saveLocale === true ? localStorage.getItem(storageKey) : null;
        if (!locale) locale = getBrowserLanguage(window.navigator);
        if (saveLocale === true) localStorage.setItem(storageKey, locale);
        if (!locale) locale = defaultLocale;
        const route = getToRoute(locale.toLowerCase());
        console.log([new URL(window.location.href).origin, route, 'index.html'].join('/'));
        window.location.replace([new URL(window.location.href).origin, route, 'index.html'].join('/'));
      })();
    </script>
  </head>
</html>

Note: Capacitor require path/index.html. So subpath cannot be restored.

1reaction
meriturvacommented, Sep 29, 2022

Thanks @UltraCakeBakery for your feedback.

My idea is to pack capacitor with all language folders produced by ng build and add an index.html file on the root folder. The root index file has just to check the device’s preferred language and redirects to the correct folder.

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fire Apparatus Access Roads
Access Road Location Requirements. Fire department access roads must be provided so fire apparatus can drive within 50 ft (15 m) of an...
Read more >
Cargo Securement Rules | FMCSA
Loaded vehicles with a high center of gravity roll over at a lateral acceleration above 0.35 g. Lightly loaded vehicles, or heavily loaded...
Read more >
API — Flask Documentation (2.2.x)
static_url_path (Optional[str]) – can be used to specify a different path for the static files on the web. Defaults to the name of...
Read more >
Wide Load Regulations, Rules, Flags and Permit Costs by ...
Any load that exceeds 16 feet in width becomes a "superload" and subject to more requirements to ensure that the load can be...
Read more >
Article 230 - Services
Conductors and equipment on the load side of service equipment are considered ... Service conductors cannot pass through the interior of another building...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found