feat: internationalization #43
							
								
								
									
										14
									
								
								src/server/internationalization.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/server/internationalization.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					use std::env;
 | 
				
			||||||
 | 
					use dioxus::prelude::ServerFnError;
 | 
				
			||||||
 | 
					use unic_langid_impl::LanguageIdentifier;
 | 
				
			||||||
 | 
					use dioxus::prelude::*;
 | 
				
			||||||
 | 
					use dotenvy::dotenv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[server]
 | 
				
			||||||
 | 
					pub(crate) async fn get_language_identifier() -> Result<LanguageIdentifier, ServerFnError> {
 | 
				
			||||||
 | 
					    dotenv().expect("Could not load environment variables from the .env file.");
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Ok(env::var("LANGUAGE_CODE")
 | 
				
			||||||
 | 
					        .expect("The environment variable LANGUAGE_CODE must be set.")
 | 
				
			||||||
 | 
					        .parse::<LanguageIdentifier>()?)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 | 
				|||||||
@@ -2,3 +2,4 @@ mod database_connection;
 | 
				
			|||||||
pub(crate) mod projects;
 | 
					pub(crate) mod projects;
 | 
				
			||||||
pub(crate) mod tasks;
 | 
					pub(crate) mod tasks;
 | 
				
			||||||
pub(crate) mod subtasks;
 | 
					pub(crate) mod subtasks;
 | 
				
			||||||
 | 
					pub(crate) mod internationalization;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user
	
LGTM with nitpicks!
The server-side code for retrieving the language identifier looks good. Just a couple of nitpicks:
If the
LANGUAGE_CODEenvironment variable is always set by the deployment process, you can remove thedotenvimport and thedotenv()call.Consider changing the visibility modifier from
pub(crate)topubfor consistency with other server functions, unless you have a specific reason to restrict the visibility to the current crate.