Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@digitak/cox
Advanced tools
Cox is an modern fully-typed Typescript and SvelteKit library to handle internationalisation.
Cox is an modern fully-typed Typescript and SvelteKit library to handle internationalisation.
Comparing to standard internationalisation libraries, it has the following features:
$t('unsafe.path.to.my.key')
. It is error-prone, very annoying to write and not typed. With Cox, you'll write something like: $content.safe.path.to.my.key
, with auto-completion and the right typing.Intl
library is highly encouraged along Cox.en.json
file for every language, Cox promotes the use of multiples smaller translation files. Typically, you would apply content per-component instead of globally. This improves drastically the developper experience.Cox is a perfect choice when you develop an application with few languages (maximum 4-5 languages).
I you need to develop a product that will be translated a lot of languages, Cox is not recommended. For these use cases, we advice to use a software with an integrated graphical user interface like Weblate.
First, let's create a configuration file that describes all the languages we will implement.
/* src/locales.ts */
import { defineLocales } from "@digitak/cox"
/**
* We want to implement two languages: english and french.
* We also indicate that english is the default language.
*/
export const { defineContent, currentLocale } = defineLocales<"en" | "fr">("en")
Then let's define a content file. A content file can contains anything, as long as it contains the same type of data for every locale to implement.
For that, we use the defineContent
function that has just been returned:
/* src/content.ts */
import { defineContent } from "./locales"
export const content = defineContent({
en: {
sayHelloToWorld: `Hello world!`,
sayHelloTo: (helloTo: string) => `Hello ${helloTo}!`
},
fr: {
sayHelloToWorld: `Bonjour le monde !`,
sayHelloTo: (helloTo: string) => `Bonjour ${helloTo} !`
},
})
Now we can use our newly defined content in our svelte components:
<!-- src/component.svelte -->
<script lang="ts">
import { content } from './content'
</script>
<p>
{ $content.sayHelloToWorld }
</p>
<p>
{ $content.sayHelloTo('magnificent you') }
</p>
currentLocale
is a writable store so it is very easy to change it programmatically:
import { currentLocale } from "./locales"
currentLocale.set("fr")
Alternatively if you are inside a .svelte
file you can use the store syntax:
$currentLocale = "fr"
Thanks to the magic of stores, this will automatically update all content data in the entire application.
Cox promotes the use of one content file per component. This is ideal for codebases that will scale. As a developer, you won't get lost with one humongous json translation file.
Not all components should have their respective content file though. For example, if you follow the atomic design methodology:
atoms
and molecules
should not be related to a content file,organisms
and templates
can be related to a content file,pages
should not be related to a content file - as they import templates and organisms that have this responsibility.FAQs
Cox is an modern fully-typed Typescript and SvelteKit library to handle internationalisation.
We found that @digitak/cox demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.