npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apostrophe-i18n-debugger

v2.2.0

Published

Helps you find static text that has not been wrapped for internationalization, or find the right translation key to translate something.

Downloads

4

Readme

CircleCI

apostrophe-i18n-debugger

This module helps you find static text in your templates that is not ready for localization and internationalization (i18n) with the i18n helpers included in ApostropheCMS. It works only when a user is logged in.

Installation

npm install apostrophe-i18n-debugger

Configuration

// in app.js, add it to your modules object
modules: {
  'apostrophe-i18n-debugger': {}
}

Don't enable this module in production. It adds overhead. You should use it in your development and/or staging environments during the initial writing of your templates.

Usage

In the admin bar you will see an "i18n 🐞" button.

Click that button to open the i18n debugger modal, then click "Activate" to wrap each translated piece of text wrapped ⸨ like this⸩. The page will refresh. You are now seeing the static translations highlighted. Any text not wrapped in this way has not been translated and you may need to edit your templates to wrap it in a __('string goes here)' call, then work on translating in the locales/ folder.

Now, click "i18n debugger" again in the admin bar and then click the "Keys" button and click "Done" to clsoe the modal. You will now see the "key" that was passed to the translation helper, not the translated text. The keys are wrapped 《like this》to help you see the difference.

In your default locale, or before you start actually translating, they might not be any different. Then again you might be using keywords rather than complete sentences in your i18n helper calls, in which case they will be quite different.

When you are done, you can click "i18n 🐞" again to close the internationalization debugger.

This module is for debugging static text localization in your templates. For translation of user-entered content, see apostrophe-workflow.

Extending the module on the front end

If you have your own frontend code that manipulates text in ways that might not be apparent to the debugger, such as a Vue app, you may be interested in the following capabilities:

// Event that fires when translations are loaded
apos.on('i18nDebuggerMaps', function(obj) {
  // obj.map: properties are keys, values are translatiojns
  // obj.reverseMap: properties are translations, values are keys
});

// Event that fires on the browser side when the user toggles
// between showing keys and showing translations
apos.on('i18nDebuggerChange', function(obj) {
  if (obj.keys) {
    // we are showing keys right now
  } else {
    // we are showing translations right now
  }
});

However, note that neither of these events will fire when the debugger is first activated. This is because the server is responsible for initially reloading the page with special wrapper characters identifying the translated text. This does involve a full page refresh.

So you can trigger a fetch of the maps yourself by calling:

apos.modules['apostrophe-i18n-debugger'].retrieve(function(err, obj) {
  // obj.map: properties are keys, values are translatiojns
  // obj.reverseMap: properties are translations, values are keys
});

Note that i18nDebuggerMaps will be emitted when you call retrieve, so you might prefer to just write a handler for that and ignore the return value from the callback.

Finally, you can recognize that the debugger is active by checking:

apos.modules['apostrophe-i18n-debugger'].options.active

Note that when the debugger first activates the user is always looking at translations, not keys. You will know if this changes by listening for i18nDebuggerChange events.

Namespacing

Apostrophe has basic support for separate namespaces of i18n keys. However, because of the impact on the layout of the display, the namespace associated with a key is not displayed by the debugger. Generally it is clear from context, for instance anything in the Apostrophe admin UI is likely to be in the apostrophe namespace.

Permissions

By default, only users with the site-wide admin permission have access to the i18n debugger. If another group needs access, you can edit the group, click on the Permissions tab, and check the I18n Debugger box. If you do not see Groups on your admin bar, see the apostrophe permissions documentation for how to activate editable groups.