<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: victor zhang</title>
    <description>The latest articles on DEV Community by victor zhang (@sheepzh).</description>
    <link>https://dev.to/sheepzh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1696632%2F4b7365ee-9faa-460c-a8bb-49856d2ecc52.jpeg</url>
      <title>DEV Community: victor zhang</title>
      <link>https://dev.to/sheepzh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sheepzh"/>
    <language>en</language>
    <item>
      <title>I Just Wanted to Know Where My Browsing Time Went. Five Years Later, Firefox Recommended It.</title>
      <dc:creator>victor zhang</dc:creator>
      <pubDate>Fri, 15 May 2026 12:45:36 +0000</pubDate>
      <link>https://dev.to/sheepzh/i-just-wanted-to-know-where-my-browsing-time-went-five-years-later-firefox-recommended-it-2915</link>
      <guid>https://dev.to/sheepzh/i-just-wanted-to-know-where-my-browsing-time-went-five-years-later-firefox-recommended-it-2915</guid>
      <description>&lt;p&gt;I didn't start this project because I wanted to build a productivity app.&lt;/p&gt;

&lt;p&gt;It began with a smaller, almost embarrassing question.&lt;/p&gt;

&lt;p&gt;Where did my time go?&lt;/p&gt;

&lt;p&gt;Not in the philosophical sense. I just wanted to know why a browser tab opened “for a minute” could quietly take an hour with it. At the end of the day, the feeling was always blurry: I knew some time had disappeared, but I could not point to where, when, or how much.&lt;/p&gt;

&lt;p&gt;So I built a browser extension for myself.&lt;/p&gt;

&lt;p&gt;It recorded how long I stayed on each website, counted visits, and showed a simple chart. That was the whole product: a small mirror for my browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwoxup6y3o2fti3yufv4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwoxup6y3o2fti3yufv4f.png" alt="Dashboard showing browsing time patterns" width="800" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Five years after the first commit, that small tool has become &lt;strong&gt;Time Tracker - Web Habit Builder&lt;/strong&gt;: an open-source browser extension for Chrome, Edge, Firefox, and Firefox for Android. Across browser stores, it has maintained a 4.9+ rating, and on Firefox it has earned Mozilla's rare Recommended badge.&lt;/p&gt;

&lt;p&gt;I don't really think of this as a growth story.&lt;/p&gt;

&lt;p&gt;It's more about what happens when a private little mirror keeps running into real users, real data, real browsers, and real habits.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The first version answered the wrong question
&lt;/h2&gt;

&lt;p&gt;The first version answered a simple question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How much time did I spend on each website?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It was useful, in a narrow way.&lt;/p&gt;

&lt;p&gt;The project started in 2021. After I shared it on a small tech forum in 2022, I noticed something awkward. People installed it, opened the numbers for a few days, and then some of them drifted away.&lt;/p&gt;

&lt;p&gt;The extension was working. The data was correct.&lt;/p&gt;

&lt;p&gt;But correctness was not enough.&lt;/p&gt;

&lt;p&gt;A number can be honest and still feel empty. “You spent 3 hours on YouTube today” doesn't automatically make anyone more aware. Sometimes it only adds guilt. Sometimes it fades into background noise. A number alone doesn't explain a pattern.&lt;/p&gt;

&lt;p&gt;That was the first time I realized:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tracking is not the value. Recognition is the value.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the product slowly moved away from raw records and toward something users could actually recognize.&lt;/p&gt;

&lt;p&gt;Compared with the version I wrote about in 2022, the biggest change is not more charts. The product now has two surfaces with different jobs.&lt;/p&gt;

&lt;p&gt;The popup became a small daily cockpit: quick enough to answer what is happening right now. The dashboard became slower and more reflective: top sites, long-term trends, calendar heatmaps, and recent activity timelines.&lt;/p&gt;

&lt;p&gt;The point is not to make the data look impressive. It is to make a messy browsing day recognizable.&lt;/p&gt;

&lt;p&gt;Your day is not just “too much browsing.” It has a shape.&lt;/p&gt;

&lt;p&gt;You open it and notice: this month was heavier than last month. The busiest time is not when you thought it was. One site is harmless on weekdays, then quietly takes over the weekend.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Users did not ask for more charts. They asked for help.
&lt;/h2&gt;

&lt;p&gt;Once people could see their behavior, the next request became obvious.&lt;/p&gt;

&lt;p&gt;Can it stop me?&lt;/p&gt;

&lt;p&gt;That was when the product stopped being easy.&lt;/p&gt;

&lt;p&gt;A time tracker is mostly passive. It observes. It records. It shows things.&lt;/p&gt;

&lt;p&gt;A site blocker is different. It interrupts the user.&lt;/p&gt;

&lt;p&gt;And the strange thing about this type of blocker is that the user is on both sides of the system. The calm version of the user creates a rule. The tired version of the user tries to bypass it.&lt;/p&gt;

&lt;p&gt;At first, the limit feature was simple: set a daily limit for a website, and show a blocking page when the time is used up.&lt;/p&gt;

&lt;p&gt;Then the edge cases started arriving.&lt;/p&gt;

&lt;p&gt;Some users wanted weekly limits. Some wanted per-session limits. Some wanted weekday rules, URL-level blocking, strict mode, delayed unlocks, or a “five more minutes” option that was helpful but not too easy.&lt;/p&gt;

&lt;p&gt;The rule system grew from a small condition into a real engine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsahqone7v0e1etqhqoa4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsahqone7v0e1etqhqoa4.png" alt="Limit rules" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The change that helped most was much smaller: a warning.&lt;/p&gt;

&lt;p&gt;In early versions, when time ran out, the block page appeared suddenly. It was technically correct, but emotionally rough. Users were interrupted at the worst possible moment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchqfwmbhjtcbjq9yaxlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchqfwmbhjtcbjq9yaxlm.png" alt="Blocked page" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the extension can notify the user before the limit is reached.&lt;/p&gt;

&lt;p&gt;A few minutes of warning changes the relationship. The blocker no longer feels like a trap. It feels more like a reminder from the earlier version of yourself — the version that made the rule before the impulse arrived.&lt;/p&gt;

&lt;p&gt;That small detail taught me more than some much larger rewrites.&lt;/p&gt;

&lt;p&gt;For behavior-related products, friction matters. But the timing of friction matters even more.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A good default is quieter than onboarding
&lt;/h2&gt;

&lt;p&gt;Over the next few years, the extension accumulated many features: categories, virtual sites, timelines, side panels, dark mode, import, sync, mobile support, and localization.&lt;/p&gt;

&lt;p&gt;At that point, an onboarding flow would have been easy to justify.&lt;/p&gt;

&lt;p&gt;I still didn't add one.&lt;/p&gt;

&lt;p&gt;My rule is simple: if a feature must be explained before it can be used, the interaction probably needs more work.&lt;/p&gt;

&lt;p&gt;I ended up designing the extension in layers. After installation, tracking starts automatically. Click the icon, and you get today's overview. Open the dashboard, and you see longer-term patterns. Go into options, and you can customize a lot.&lt;/p&gt;

&lt;p&gt;Power users can configure a lot, but configuration doesn't stand at the entrance. That is one of the most important product decisions in the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2ij4jjucccauuzrcctl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2ij4jjucccauuzrcctl.png" alt="Category timeline" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Privacy was not a feature checkbox. It shaped the architecture.
&lt;/h2&gt;

&lt;p&gt;The extension sits close to sensitive data.&lt;/p&gt;

&lt;p&gt;Browsing history is personal. Even if the product doesn't care about the content of pages, the pattern itself says a lot about a person.&lt;/p&gt;

&lt;p&gt;So from the beginning, I avoided accounts, servers, and analytics collection. The data stays local by default.&lt;/p&gt;

&lt;p&gt;Later, users asked for cross-device backup and remote query. Instead of building my own cloud service, I added user-controlled sync options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Gist&lt;/li&gt;
&lt;li&gt;Obsidian local REST API&lt;/li&gt;
&lt;li&gt;WebDAV&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That means users bring their own storage. The extension provides the integration, but doesn't become the data owner.&lt;/p&gt;

&lt;p&gt;This decision made some things harder. There is no central backend to debug. Different WebDAV servers behave differently. Obsidian users have different local setups. Gist has its own API limits and edge cases.&lt;/p&gt;

&lt;p&gt;But it fits the product.&lt;/p&gt;

&lt;p&gt;A tool about personal habits shouldn't quietly become another place where personal history is collected.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Long-term users and real browsers changed the engineering priorities
&lt;/h2&gt;

&lt;p&gt;The product looked simple when the data was small and the browser target was mostly Chrome.&lt;/p&gt;

&lt;p&gt;Then the history started doing what history does: it piled up.&lt;/p&gt;

&lt;p&gt;After two or three years of daily tracking, browsing history was no longer a small settings object. It had become time-series data: large, structured, and constantly queried. Reports became slower. Popup loading became heavier. The product was starting to punish the users who had trusted it the longest.&lt;/p&gt;

&lt;p&gt;So in v4.0, I moved tracking data to IndexedDB. The goal was not to show off a new architecture. The goal was quieter: heavy users should update, keep their history, and simply feel that the product had become lighter.&lt;/p&gt;

&lt;p&gt;Firefox brought a similar reminder from another direction. Browser extensions only look standardized from a distance. Background behavior, sidebar APIs, Android support, and Manifest V3 details all differ enough to matter.&lt;/p&gt;

&lt;p&gt;Supporting Firefox well meant making the cross-browser design more explicit: separate platform behavior where needed, fewer assumptions from one browser, and more testing around the places where users actually feel the difference.&lt;/p&gt;

&lt;p&gt;The Mozilla Recommended badge came much later. I didn't build the product for that badge. But looking back, these boring engineering decisions probably mattered: safer data migration, faster reports, fewer platform assumptions, and a product experience that feels native instead of merely compatible.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Community changed the product more than metrics did
&lt;/h2&gt;

&lt;p&gt;The product has no growth team, no ads, and no onboarding funnel.&lt;/p&gt;

&lt;p&gt;Most improvements came from users saying very specific things.&lt;/p&gt;

&lt;p&gt;A user wants to merge several domains because one service uses many subdomains. Another user wants to import data from another extension. Someone wants to track local files. Someone wants WebDAV. Someone wants Firefox Android. Someone wants the interface to feel native in their own language.&lt;/p&gt;

&lt;p&gt;Those requests were not abstract “user needs.” They were real situations.&lt;/p&gt;

&lt;p&gt;Translation is the clearest example. The project now has a Crowdin-based workflow, with English as the required source locale and partial translations allowed to fall back safely.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0jriotros275g7jh7qy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0jriotros275g7jh7qy.png" alt="Crowdin" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today it has locale targets for 14 languages.&lt;/p&gt;

&lt;p&gt;That detail matters because internationalization is not just uploading strings. The extension still has to map browser language codes, validate placeholders, generate extension metadata, and handle layout direction for RTL languages.&lt;/p&gt;

&lt;p&gt;This changed how I think about feedback.&lt;/p&gt;

&lt;p&gt;A public review is nice. But a detailed issue, a screenshot, or a carefully described routine is often more valuable. It tells you where the product is meeting real life.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Today, it is no longer just a tracker
&lt;/h2&gt;

&lt;p&gt;This is the part that changed the most since the early days.&lt;/p&gt;

&lt;p&gt;The tool started as a way to answer one narrow question: where did my browsing time go?&lt;/p&gt;

&lt;p&gt;Now, that answer is only the beginning. The project has become less about measuring time itself, and more about helping users notice the patterns around it.&lt;/p&gt;

&lt;p&gt;It's a small shift in wording, but it changed how I think about the product.&lt;/p&gt;

&lt;p&gt;A tracker records what happened. A habit system helps users recognize what keeps happening, and gives them a few ways to respond without handing their browsing history to someone else's backend.&lt;/p&gt;

&lt;p&gt;That is the current shape of the project: still simple enough to install and understand in a minute, but mature enough for people who want to work with their browsing behavior over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. What I would do differently
&lt;/h2&gt;

&lt;p&gt;If I were to start again, I would spend less time thinking about the feature list, and more time thinking about how quickly a new user could get one useful answer.&lt;/p&gt;

&lt;p&gt;A user should be able to install it, open the popup, and understand something about today without reading a guide.&lt;/p&gt;

&lt;p&gt;I would still add advanced options, but I would place them behind natural paths: reports after people have data, rules after people notice a pattern, sync after people care about history, import after people are ready to switch.&lt;/p&gt;

&lt;p&gt;There are technical things I would do earlier, of course: IndexedDB, integration tests, and more explicit cross-browser design.&lt;/p&gt;

&lt;p&gt;But the simpler lesson is the one I keep coming back to: don't make users pay attention before the product has earned it. Let the default experience carry the first mile, and treat real user routines as product input, not just support work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/sheepzh/time-tracker-4-browser" rel="noopener noreferrer"&gt;sheepzh/time-tracker-4-browser&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Chrome: &lt;a href="https://chromewebstore.google.com/detail/time-tracker-web-habit-bu/dkdhhcbjijekmneelocdllcldcpmekmm" rel="noopener noreferrer"&gt;Chrome Web Store&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Edge: &lt;a href="https://microsoftedge.microsoft.com/addons/detail/time-tracker-web-habit-/fepjgblalcnepokjblgbgmapmlkgfahc" rel="noopener noreferrer"&gt;Microsoft Edge Add-ons&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firefox: &lt;a href="https://addons.mozilla.org/firefox/addon/besttimetracker/" rel="noopener noreferrer"&gt;Firefox Add-ons&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Website: &lt;a href="https://www.wfhg.cc" rel="noopener noreferrer"&gt;www.wfhg.cc&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you are building a small product that started as a personal tool, I would love to hear what changed when real users walked in.&lt;/p&gt;

</description>
      <category>browserextensions</category>
      <category>opensource</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Use i18n with TypeScript checks</title>
      <dc:creator>victor zhang</dc:creator>
      <pubDate>Fri, 28 Jun 2024 06:16:15 +0000</pubDate>
      <link>https://dev.to/sheepzh/use-i18n-with-typescript-checks-9j3</link>
      <guid>https://dev.to/sheepzh/use-i18n-with-typescript-checks-9j3</guid>
      <description>&lt;p&gt;I tried a simple way to check i18n resources with TypeScript to reduce errors. Here share it with you guys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Firstly, enable &lt;code&gt;resolveJsonModule&lt;/code&gt; in your tsconfig.json
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"resolveJsonModule"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Define the type for locales
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en_US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zh_CN&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Define the type for messages
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Messages&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;Locale&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Define the type for your resource
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;AboutMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
       &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nl"&gt;tip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;feedback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Edit resource json file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"en_US"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"label"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"My App"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"tip"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"feedback"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"This is a feedback link"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"zh_CN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"label"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"我的应用"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"版本"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"tip"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"feedback"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"这是反馈链接"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And then, define &lt;code&gt;t()&lt;/code&gt; function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../app-resource.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;// Use this to check if your resource file is correct&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Messages&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AboutMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt;

&lt;span class="c1"&gt;// Define a function key to get snippet tips while invoking t()&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AboutMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Locale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;?.(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ignored */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;?.(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en_US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ignored again */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, you can use it like this, or integrate it into other frameworks
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;feedbackTip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;feedback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en_US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real Project
&lt;/h2&gt;

&lt;p&gt;The above is just a simple example of my idea, you can extend it according to your project. &lt;/p&gt;

&lt;p&gt;And I applied it to my own project &lt;a href="https://github.com/sheepzh/timer"&gt;Time Tracker&lt;/a&gt; which is a browser extension helping people track the time spent on each website. &lt;/p&gt;

&lt;p&gt;Thanks for reading&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>i18n</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
