Skip to content

Commit a2bd68c

Browse files
committed
docs: refresh README
1 parent 848b01b commit a2bd68c

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

README.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ This package detects when a page is translated on the client (using, for example
44

55
[![npm version](https://badge.fury.io/js/detect-translation.svg)](https://badge.fury.io/js/detect-translation)
66

7+
## What You Get
8+
9+
- Detects translation type: `client`, `proxy`, or `unknown`
10+
- Detects translation service: `google`, `bing`, `yandex`, `baidu`, etc
11+
- Reports the target language via the document `<html lang="...">` attribute (plus heuristics for services that don’t set it reliably)
12+
713
## Supported translators
814

915
`detect-translation` can currently detect the following services:
@@ -36,9 +42,9 @@ This package detects when a page is translated on the client (using, for example
3642
pnpm add detect-translation
3743
```
3844

39-
_You can use npm or yarn if you prefer_
45+
_You can use npm or yarn if you prefer: `npm i detect-translation`, `yarn add detect-translation`_
4046

41-
The package was written in Typescript, so no need to install types separately.
47+
The package is written in TypeScript and ships its own types.
4248

4349
---
4450

@@ -49,18 +55,36 @@ import { observe } from "detect-translation";
4955

5056
observe({
5157
onTranslation: (lang, { service, type }) => {
52-
// type will be 'proxy', 'client' or 'unknown'
53-
// service will be for example, 'google', 'bing', 'yandex', 'baidu' etc
54-
// lang will be the BCP 47 code, for example zh, fr, ru, de, hi, es, pt etc
58+
// type: "proxy" | "client" | "unknown"
59+
// service: e.g. "google", "bing", "yandex", "baidu" (see Services enum)
60+
// lang: a BCP 47-ish language tag (e.g. "zh", "fr", "ru", "de", "hi", "es", "pt")
5561
console.log(`${type} translation using ${service}, language ${lang}`);
5662
},
5763
sourceLang: "en",
5864
});
5965
```
6066

61-
Ensure that the script that calls `observe` is executed _after_ your HTML content.
67+
Ensure the script that calls `observe` runs after your HTML content is in the DOM.
68+
69+
`lang` is based on the `<html>` [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) (set by the translation service when possible), or identified heuristically if you provide a “Skip to main content” link (see below).
70+
71+
## Browser usage (no bundler)
72+
73+
This package also ships a browser bundle that exposes a global `DetectTranslation` (useful for CDN usage).
74+
75+
```html
76+
<script src="https://unpkg.com/detect-translation@latest/dist-browser/index.min.js"></script>
77+
<script>
78+
DetectTranslation.observe({
79+
sourceLang: "en",
80+
onTranslation: function (lang, info) {
81+
console.log(info.type, info.service, lang);
82+
},
83+
});
84+
</script>
85+
```
6286

63-
`lang` is the value of the `<html>` [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) - this gets set by the translation service (or identified heuristically if you provide a “Skip to main content” link; see below).
87+
If you use a bundler, prefer the module import shown in “Getting started”.
6488

6589
## Advanced usage
6690

@@ -147,4 +171,30 @@ It’s quite possible to use another phrase to identify translated content langu
147171

148172
---
149173

174+
## Development
175+
176+
This repository uses `pnpm`.
177+
178+
Common commands:
179+
180+
```bash
181+
pnpm install
182+
pnpm test
183+
pnpm run lint # biome
184+
pnpm run knip # dead-code / unused deps
185+
pnpm run build
186+
pnpm run prepublish # the main verification gate (tests + lint + typecheck + knip + build + checks)
187+
```
188+
189+
### Releases
190+
191+
Releases are tag-driven:
192+
193+
1. Bump `package.json` version.
194+
2. Create and push a tag like `v0.2.1`.
195+
196+
GitHub Actions will run sanity checks and then publish to npm (requires the `NPM_TOKEN` repo secret), and create a GitHub Release with autogenerated notes.
197+
198+
---
199+
150200
MIT @ [Claudiu Ceia](https://github.com/ClaudiuCeia)

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"files": {
99
"includes": [
10-
"**",
10+
"**/*",
1111
"!!**/dist",
1212
"!!**/dist-browser",
1313
"!!**/pkg",

0 commit comments

Comments
 (0)