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.
@dfxx/translate
Advanced tools
A simple translation package for Angular 4 - 12.
npm install dfx-translate@latest
Language files must be saved in src/assets/i18n/LANGUAGE_CODE.json
; Create the directory if it does not exist.
mkdir -p ./src/assets/i18n
Choose a primary language, lets say you've picked english. Create an en.json
file with following content:
{
"WELCOME": "Welcome",
"WELCOME_SUBTEXT": "stranger."
}
Note: The json structure must always consist of a key and value pair.
Choose an additional language, lets say you've picked german. Create an de.json
file
{
"WELCOME": "Willkomen",
"WELCOME_SUBTEXT": "Fremder."
}
Note: You do not have to translate all strings if you are using the auto-translate feature.
dfx-translate can translate the primary language into a whole new language and will take partially manual translated
languages into account, meaning it will only translate strings which are not occurring in the manual created files
located at src/assets/i18n/LANGUAGE_CODE.json
.
This has to be done only once in the project. Ideal in app.module.ts
import {DfxTranslateModule} from "dfx-translate";
@NgModule({
declarations: [...],
imports: [
...
DfxTranslateModule.setup({
configuration: {
defaultLanguage: 'de',
useLocalStorage: false
}
})
],
bootstrap: [...]
})
export class AppModule {
}
property | description | default value |
---|---|---|
defaultLanguage | Short code of the primary language (identically to the file name) | en |
useLocalStorage | Saves selected languages as the preference into local storage | true |
import {DfxTranslateModule} from "dfx-translate";
@NgModule({
declarations: [...],
imports: [
...
DfxTranslateModule,
],
})
export class FeatureModule {
}
Language switching is as easy as one function call.
Note: The language code used has to exist as src/assets/i18n/LANGUAGE_CODE.json
import {TranslateService} from "dfx-translate";
@Component({
selector: 'app-example',
templateUrl: ...,
styleUrls: [...],
})
export class ExampleComponent {
constructor(private translator: TranslateService) {
}
setLang(lang: string) {
this.translator.use(lang);
}
}
Import DfxTranslateModule
into the module requiring the translation pipe.
import {DfxTranslateModule} from "dfx-translate";
@NgModule({
declarations: [...],
imports: [
...
DfxTranslateModule,
...
],
exports: [...]
})
export class ExampleModule {
}
Now you can use it with tr
in html
<h1>{{'WELCOME' | tr}}</h1>
<span>{{'WELCOME_SUBTEXT' | tr}}</span>
Access translations via code with TranslateService
import {TranslateService} from "dfx-translate";
@Component({
selector: 'app-example',
templateUrl: ...,
styleUrls: [...],
})
export class ExampleComponent {
constructor(private translator: TranslateService) {
}
save() {
window.alert(this.translator.translate('WELCOME'));
}
}
It's possible to translate not manual translated strings via LibreTranslate API. LibreTranslate is an open-source, self-hostable machine-translation service.
dfx-translate can translate the primary language into a whole new language and will take partially manual translated languages into account, meaning it will only translate strings which are not occurring in the manual created files located at src/assets/i18n/LANGUAGE_CODE.json.
Command syntax:
node ./node_modules/dfx-translate/translation/generateTranslation.js {API_URL} {SOURCE_LANGUAGE_CODE} {TARGET_LANGUAGE_CODE}
Note: You never have to auto-translate fully manual translated files
LANGUAGE_CODE | name |
---|---|
en | English |
ar | Arabic |
zh | Chinese |
fr | French |
de | German |
hi | Hindi |
ga | Irish |
it | Italian |
ja | Japanese |
ko | Korean |
pt | Portuguese |
ru | Russian |
es | Spanish |
Note: Keep in mind that at least one of the fully manual translated files has to be in such a language for this feature to work.
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en es
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en fr
Following files should be in src/assets/i18n/
folder.
en.json
- the primary languagede.json
- additional language, fully manual translatedes.json
- additional language, partially manual translatedes_auto.json
- additional language, auto-translated missing strings of es.json
compared to the primary languagefr_auto.json
- additional language, completely auto-translated containing all translationsFor simplicity purposes I wrote a little shell script. Put this at the top / root level of the project
#!/usr/bin/env bash
main () {
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en de
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en fr
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en es
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en it
node ./node_modules/dfx-translate/translation/generateTranslation.js https://translate.abc.abc/translate en pt
# If you have any prettier library intstalled, execute it here
# prettier --config ./.prettierrc --write ./src/assets/i18n
printf "\nFinished!"
}
time main
Now you only have to run this script.
Everything important in this library is located in projects/dfx-translate
, that's the "real" library. (following
commands still have to be executed at the root level)
npm install
npm run-script watch
npm run-script build
dfx-translate deployments are managed via .gitlab-ci
All builds are uploaded to releases.datepoll.org/common/dfx-translate
Commits to the development branch create a dev build downloadable via this link.
Tags create a release build downloadable via this link. Additionally, a versioned zip is uploaded and the package is published to npm.
FAQs
A simple translation package for Angular 4 - 12.
The npm package @dfxx/translate receives a total of 0 weekly downloads. As such, @dfxx/translate popularity was classified as not popular.
We found that @dfxx/translate 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.