prepare to move strings to the /scripts folder
This commit is contained in:
		
							parent
							
								
									9dfdb3f44b
								
							
						
					
					
						commit
						c03d7521f3
					
				
					 2 changed files with 55 additions and 2 deletions
				
			
		|  | @ -2,7 +2,7 @@ | ||||||
| // Import the file module.
 | // Import the file module.
 | ||||||
| // import file from `./net.js`;
 | // import file from `./net.js`;
 | ||||||
| 
 | 
 | ||||||
| const texts = (await import(chrome.runtime.getURL("scripts/read.js"))).default; | const texts = (await import(chrome.runtime.getURL("scripts/strings/read.js"))).default; | ||||||
| 
 | 
 | ||||||
| // Don't forget to set the class as export default.
 | // Don't forget to set the class as export default.
 | ||||||
| export default class gemini { | export default class gemini { | ||||||
|  | @ -17,7 +17,7 @@ export default class gemini { | ||||||
|     */ |     */ | ||||||
|     constructor (key, model, version = {"API": "v1beta"}) { |     constructor (key, model, version = {"API": "v1beta"}) { | ||||||
|         if ((key) ? (((typeof key).includes(`str`)) ? !(key.trim()) : true) : true) { |         if ((key) ? (((typeof key).includes(`str`)) ? !(key.trim()) : true) : true) { | ||||||
|             throw new ReferenceError(texts.localized(`error_msg_APImissing`)); |             throw new ReferenceError((new texts(`error_msg_APImissing`)).localized); | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         // Register the API key privately.
 |         // Register the API key privately.
 | ||||||
|  |  | ||||||
							
								
								
									
										53
									
								
								scripts/strings/read.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								scripts/strings/read.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,53 @@ | ||||||
|  | /* read_universal | ||||||
|  |   Read a file stored in the universal strings. */ | ||||||
|  | 
 | ||||||
|  | let messages = {}; | ||||||
|  | let message = ""; | ||||||
|  | 
 | ||||||
|  | export default class texts { | ||||||
|  |   /* This reads the message from its source. This is a fallback for the content scripts, who doesn't appear to read classes. | ||||||
|  | 
 | ||||||
|  |   @param {string} message the message name | ||||||
|  |   @param {boolean} autofill fill in the message with the template name when not found | ||||||
|  |   @param {list} params the parameters | ||||||
|  |   @return {string} the message | ||||||
|  |   */ | ||||||
|  | 
 | ||||||
|  |   constructor(message_name, autofill = false, params = []) { | ||||||
|  |     if (params && (params ? params.length > 0 : false)) { | ||||||
|  |       this.localized = chrome.i18n.getMessage(message_name, params); | ||||||
|  |     } else { | ||||||
|  |       this.localized = chrome.i18n.getMessage(message_name); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // When the message is not found, return the temporary text.
 | ||||||
|  |     if (!this.localized && autofill) { | ||||||
|  |       this.localized = message_name; | ||||||
|  |     } else if (!this.localized && !autofill) { | ||||||
|  |       delete this.localized; | ||||||
|  |     }; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static localized(message_name, autofill = false, params = []) { | ||||||
|  |     if (params && (params ? params.length > 0 : false)) { | ||||||
|  |       message = chrome.i18n.getMessage(message_name, params); | ||||||
|  |     } else { | ||||||
|  |       message = chrome.i18n.getMessage(message_name); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // When the message is not found, return the temporary text.
 | ||||||
|  |     if (!message && autofill) { | ||||||
|  |       message = message_name; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return message; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export function read(message_name, autofill, params) { | ||||||
|  |   let message; | ||||||
|  | 
 | ||||||
|  |   message = texts.localized(message_name, autofill, params); | ||||||
|  | 
 | ||||||
|  |   return message; | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue