Gettext in JavaScript

@gettext loads the translations of the current language and the translation functions. Put it into the layout before your own scripts:
resources/views/layouts/app.blade.php
@translates is the same directive. It adds:
  • the translations script /vendor/js/ca-translates.js, cached by the browser until the translations change
  • the global functions _(), __(), ngettext(), n__(), p__() and the other gettext functions. A function is skipped when a global with the same name already exists, e.g. _ of lodash.
  • the action() function
  • the frontend editor for administrators with access
resources/js/app.js
The functions are described in Localization.

Separate frontends

With gettext.json enabled, /vendor/js/ca-translates-json.js returns the translations as JSON. Frontends with their own build, e.g. Nuxt, load them into the @crudadmin/helpers translator.

Urls of routes

Mark routes which JavaScript calls with visible():
routes/web.php
@gettext prints their urls, and action() returns them by the controller action. Route parameters are replaced in their order:
The action is relative to the controller namespace App\Http\Controllers, e.g. Frontend\ContactController@store. Register it in Vue with app.use(action), then use this.action() in components. Use controller actions for visible routes. Routes with a closure have no controller to look up.
In CrudAdmin 6, the administration itself no longer installs window.action(). It is available only on pages with @gettext.

Obfuscated e-mails

encryptText() hides e-mails and phone numbers from spam robots. @gettext decodes elements with the toEncrypt class after the page loads. toEncryptHref decodes only the href. Encode the whole href value, including mailto: or tel:.
Decode a value in your own script with decryptText(value).
This is obfuscation, not encryption. Anyone can decode the value, so never use it for secrets.