| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  | const languages = [ | 
					
						
							|  |  |  |     'ar-SA', | 
					
						
							|  |  |  |     'ca-ES', | 
					
						
							|  |  |  |     'de-DE', | 
					
						
							|  |  |  |     'en', | 
					
						
							|  |  |  |     'es-VE', | 
					
						
							|  |  |  |     'eu-ES', | 
					
						
							|  |  |  |     'fr-FR', | 
					
						
							|  |  |  |     'hu-HU', | 
					
						
							|  |  |  |     'id-ID', | 
					
						
							|  |  |  |     'it-IT', | 
					
						
							|  |  |  |     'ja-JP', | 
					
						
							|  |  |  |     'ko-KR', | 
					
						
							|  |  |  |     'pl-PL', | 
					
						
							|  |  |  |     'pt-BR', | 
					
						
							|  |  |  |     'pt-PT', | 
					
						
							|  |  |  |     'ru-RU', | 
					
						
							| 
									
										
										
										
											2023-11-08 14:13:17 +08:00
										 |  |  |     'sv-SE', | 
					
						
							| 
									
										
										
										
											2023-11-23 11:40:09 +07:00
										 |  |  |     'th-TH', | 
					
						
							| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  |     'tr-TR', | 
					
						
							|  |  |  |     'zh-CN', | 
					
						
							|  |  |  |     'zh-TW', | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | languages.forEach(language => { | 
					
						
							|  |  |  |     const json = require(`../../../resources/translations/${language}.json`); | 
					
						
							|  |  |  |     const outputJSON = flattenJSON(json); | 
					
						
							|  |  |  |     const output = JSON.stringify(outputJSON); | 
					
						
							|  |  |  |     const isExistDir = fs.existsSync('./src/appflowy_app/i18n/translations'); | 
					
						
							|  |  |  |     if (!isExistDir) { | 
					
						
							|  |  |  |         fs.mkdirSync('./src/appflowy_app/i18n/translations'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     fs.writeFile(`./src/appflowy_app/i18n/translations/${language}.json`, new Uint8Array(Buffer.from(output)), (res) => { | 
					
						
							|  |  |  |         if (res) { | 
					
						
							|  |  |  |             console.error(res); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2023-12-04 10:33:31 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  | function flattenJSON(obj, prefix = '') { | 
					
						
							|  |  |  |     let result = {}; | 
					
						
							| 
									
										
										
										
											2023-12-04 10:33:31 +08:00
										 |  |  |     const pluralsKey = ["one", "other", "few", "many", "two", "zero"]; | 
					
						
							| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (let key in obj) { | 
					
						
							|  |  |  |         if (typeof obj[key] === 'object' && obj[key] !== null) { | 
					
						
							| 
									
										
										
										
											2023-12-04 10:33:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  |             const nestedKeys = flattenJSON(obj[key], `${prefix}${key}.`); | 
					
						
							|  |  |  |             result = { ...result, ...nestedKeys }; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-12-04 10:33:31 +08:00
										 |  |  |             let newKey = `${prefix}${key}`; | 
					
						
							|  |  |  |             let replaceChar = '{' | 
					
						
							|  |  |  |             if (pluralsKey.includes(key)) { | 
					
						
							|  |  |  |                 newKey = `${prefix.slice(0, -1)}_${key}`; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             result[newKey] = obj[key].replaceAll('{', '{{').replaceAll('}', '}}'); | 
					
						
							| 
									
										
										
										
											2023-07-12 11:54:50 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |