add function to look for symbols
Symbols can also be Unicode emojis.
This commit is contained in:
		
							parent
							
								
									08ed48e4a2
								
							
						
					
					
						commit
						007435683d
					
				
					 1 changed files with 52 additions and 41 deletions
				
			
		|  | @ -1,53 +1,64 @@ | ||||||
| /* read_universal | /* read_universal | ||||||
|   Read a file stored in the universal strings. */ | 	Read a file stored in the universal strings. */ | ||||||
| 
 |  | ||||||
| let messages = {}; |  | ||||||
| let message = ""; |  | ||||||
| 
 | 
 | ||||||
| export default class texts { | 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. | 	/* 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 {string} message the message name | ||||||
|   @param {boolean} autofill fill in the message with the template name when not found | 	@param {boolean} autofill fill in the message with the template name when not found | ||||||
|   @param {list} params the parameters | 	@param {list} params the parameters | ||||||
|   @return {string} the message | 	@return {string} the message | ||||||
|   */ | 	*/ | ||||||
| 
 | 
 | ||||||
|   constructor(message_name, autofill = false, params = []) { | 	constructor(message_name, autofill = false, params = []) { | ||||||
|     if (params && (params ? params.length > 0 : false)) { | 		[`localized`, `symbol`].forEach((SOURCE) => { | ||||||
|       this.localized = chrome.i18n.getMessage(message_name, params); | 			this[SOURCE] = texts[SOURCE](message_name, autofill, params); | ||||||
|     } else { |  | ||||||
|       this.localized = chrome.i18n.getMessage(message_name); |  | ||||||
|     } |  | ||||||
| 			 | 			 | ||||||
|     // When the message is not found, return the temporary text.
 | 			// When the message is not found, return the temporary text.
 | ||||||
|     if (!this.localized && autofill) { | 			(!this[SOURCE] && !autofill) ? delete this[SOURCE] : false; | ||||||
|       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.
 | 	static localized(message_name, autofill = false, params = []) { | ||||||
|     if (!message && autofill) { | 		let MESSAGE = (params && (params ? params.length > 0 : false)) | ||||||
|       message = message_name; | 			? chrome.i18n.getMessage(message_name, params) | ||||||
|     } | 			: chrome.i18n.getMessage(message_name); | ||||||
| 
 | 
 | ||||||
|     return message; | 		// When the message is not found, return the temporary text.
 | ||||||
|   } | 		(!MESSAGE && autofill)  | ||||||
|  | 			? MESSAGE = message_name | ||||||
|  | 			: false; | ||||||
|  | 
 | ||||||
|  | 		return (MESSAGE); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	/* | ||||||
|  | 	Look for a symbol.  | ||||||
|  | 	 | ||||||
|  | 	@param {string} message_name the symbol name | ||||||
|  | 	@param {bool} autofill use the message name if the message is not found | ||||||
|  | 	@param {object} params the parameters | ||||||
|  | 	*/ | ||||||
|  | 	static symbol(message_name, autofill = false, params = []) { | ||||||
|  | 		const CONFIG = chrome.runtime.getURL("media/config.symbols.json"); | ||||||
|  | 		return (fetch(CONFIG) | ||||||
|  | 			.then((response) => response.json()) | ||||||
|  | 			.then((jsonData) => { | ||||||
|  | 				let SYMBOL = (autofill) ? message_name : null; | ||||||
|  | 				 | ||||||
|  | 				(jsonData[message_name]) | ||||||
|  | 					? SYMBOL = jsonData[message_name][`symbol`] | ||||||
|  | 					: false; | ||||||
|  | 				 | ||||||
|  | 				return (SYMBOL); | ||||||
|  | 			}) | ||||||
|  | 			.catch((error) => { | ||||||
|  | 				console.error(error); | ||||||
|  | 			})); | ||||||
|  | 	}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function read(message_name, autofill, params) { | export function read(message_name, autofill, params) { | ||||||
|   let message; | 	return (texts.localized(message_name, autofill, params)); | ||||||
| 
 |  | ||||||
|   message = texts.localized(message_name, autofill, params); |  | ||||||
| 
 |  | ||||||
|   return message; |  | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue