MCPcopy Index your code
hub / github.com/darkreader/darkreader / parseLocale

Function parseLocale

tasks/translate.js:108–130  ·  view source on GitHub ↗

* @param {string} content * @returns {Map }

(content)

Source from the content-addressed store, hash-verified

106 * @returns {Map<string, string>}
107 */
108function parseLocale(content) {
109 /** @type {Map<string, string>} */
110 const messages = new Map();
111 const lines = content.split('\n');
112 let id = '';
113 for (let i = 0; i < lines.length; i++) {
114 const line = lines[i];
115 if (line.startsWith('@')) {
116 id = line.substring(1);
117 } else if (line.startsWith('#')) {
118 // Ignore
119 } else if (messages.has(id)) {
120 const message = messages.get(id);
121 messages.set(id, `${message}\n${line}`);
122 } else {
123 messages.set(id, line);
124 }
125 }
126 messages.forEach((value, id) => {
127 messages.set(id, value.trim());
128 });
129 return messages;
130}
131
132/**
133 * @param {Map<string, string>} messages

Callers 2

translateEnMessageFunction · 0.85
translateNewEnMessagesFunction · 0.85

Calls 3

hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected