Quick fix for i18n
Just use the english locale for now. Load locale data from the filesystem in the main process and pass it to the renderer preload script via ipc. Note that we need the locale data to be available by the time view scripts are loaded. // FREEBIE
This commit is contained in:
		
					parent
					
						
							
								88893079d2
							
						
					
				
			
			
				commit
				
					
						63657db3be
					
				
			
		
					 5 changed files with 51 additions and 12 deletions
				
			
		|  | @ -731,6 +731,7 @@ | ||||||
|   <script type='text/javascript' src='js/conversation_controller.js'></script> |   <script type='text/javascript' src='js/conversation_controller.js'></script> | ||||||
|   <script type='text/javascript' src='js/panel_controller.js'></script> |   <script type='text/javascript' src='js/panel_controller.js'></script> | ||||||
|   <script type='text/javascript' src='js/emoji_util.js'></script> |   <script type='text/javascript' src='js/emoji_util.js'></script> | ||||||
|  |   <script type='text/javascript' src='js/i18n.js'></script> | ||||||
| 
 | 
 | ||||||
|   <script type='text/javascript' src='js/views/whisper_view.js'></script> |   <script type='text/javascript' src='js/views/whisper_view.js'></script> | ||||||
|   <script type='text/javascript' src='js/views/last_seen_indicator_view.js'></script> |   <script type='text/javascript' src='js/views/last_seen_indicator_view.js'></script> | ||||||
|  |  | ||||||
|  | @ -153,17 +153,19 @@ | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     // Translate
 |     // Translate
 | ||||||
|  | 
 | ||||||
|  |     if (window.chrome && window.chrome.i18n) { | ||||||
|       window.i18n = function(message, substitutions) { |       window.i18n = function(message, substitutions) { | ||||||
|         if (window.chrome && chrome.i18n) { |  | ||||||
|           return chrome.i18n.getMessage(message, substitutions); |           return chrome.i18n.getMessage(message, substitutions); | ||||||
|         } |  | ||||||
|       }; |       }; | ||||||
|  | 
 | ||||||
|       i18n.getLocale = function() { |       i18n.getLocale = function() { | ||||||
|           if (window.chrome && chrome.i18n) { |           if (window.chrome && chrome.i18n) { | ||||||
|               return chrome.i18n.getUILanguage(); |               return chrome.i18n.getUILanguage(); | ||||||
|           } |           } | ||||||
|           return 'en'; |           return 'en'; | ||||||
|       }; |       }; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     extension.install = function(mode) { |     extension.install = function(mode) { | ||||||
|         if (mode === 'standalone') { |         if (mode === 'standalone') { | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								js/i18n.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								js/i18n.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | ||||||
|  | /* | ||||||
|  |  * vim: ts=4:sw=4:expandtab | ||||||
|  |  */ | ||||||
|  | ;(function() { | ||||||
|  |     'use strict'; | ||||||
|  |     var json = window.env.locale_json; | ||||||
|  |     window.i18n = function (message, substitutions) { | ||||||
|  |       var s = json[message] ? json[message].message : message; | ||||||
|  |       if (substitutions instanceof Array) { | ||||||
|  |         substitutions.forEach(function(sub) { | ||||||
|  |           s = s.replace(/\$.+?\$/, sub); | ||||||
|  |         }); | ||||||
|  |       } else if (substitutions) { | ||||||
|  |         s = s.replace(/\$.+?\$/, substitutions); | ||||||
|  |       } | ||||||
|  |       return s; | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     i18n.getLocale = function() { | ||||||
|  |       return window.env.locale; | ||||||
|  |     }; | ||||||
|  | })(); | ||||||
							
								
								
									
										13
									
								
								main.js
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								main.js
									
										
									
									
									
								
							|  | @ -6,6 +6,7 @@ const url = require('url') | ||||||
| const fs = require('fs') | const fs = require('fs') | ||||||
| const autoUpdater = require('electron-updater').autoUpdater | const autoUpdater = require('electron-updater').autoUpdater | ||||||
| const autoUpdaterInterval = 60 * 60 * 1000; | const autoUpdaterInterval = 60 * 60 * 1000; | ||||||
|  | const ipc = electron.ipcMain; | ||||||
| 
 | 
 | ||||||
| app.setAppUserModelId('org.whispersystems.signal-desktop') | app.setAppUserModelId('org.whispersystems.signal-desktop') | ||||||
| 
 | 
 | ||||||
|  | @ -47,12 +48,22 @@ function createWindow () { | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|  |   // Load locale
 | ||||||
|  |   const locale = 'en'; // FIXME
 | ||||||
|  |   const localeData = JSON.parse(fs.readFileSync(path.join(__dirname, '_locales', locale, 'messages.json'), 'utf-8')) | ||||||
|  |   ipc.on('locale-data', function(event, arg) { | ||||||
|  |     event.returnValue = localeData; | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   // and load the index.html of the app.
 |   // and load the index.html of the app.
 | ||||||
|   mainWindow.loadURL(url.format({ |   mainWindow.loadURL(url.format({ | ||||||
|     pathname: path.join(__dirname, 'background.html'), |     pathname: path.join(__dirname, 'background.html'), | ||||||
|     protocol: 'file:', |     protocol: 'file:', | ||||||
|     slashes: true, |     slashes: true, | ||||||
|     query: { node_env: NODE_ENV } |     query: { | ||||||
|  |       node_env: NODE_ENV, | ||||||
|  |       locale: locale | ||||||
|  |     } | ||||||
|   })) |   })) | ||||||
| 
 | 
 | ||||||
|   // Open the DevTools.
 |   // Open the DevTools.
 | ||||||
|  |  | ||||||
|  | @ -8,3 +8,6 @@ window.location.search.substring(1).split('&').forEach(function(variable) { | ||||||
|   var pair = variable.split('='); |   var pair = variable.split('='); | ||||||
|   env[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); |   env[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | const ipc = require('electron').ipcRenderer | ||||||
|  | window.env.locale_json = ipc.sendSync('locale-data'); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 lilia
				lilia