Skip to content

Commit

Permalink
Merge pull request #38 from RedMser/class-docs
Browse files Browse the repository at this point in the history
Add class documentation
  • Loading branch information
RedMser authored Sep 7, 2024
2 parents 596884c + 7799004 commit b90ab40
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 43 deletions.
86 changes: 46 additions & 40 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rust/src/fluent/editor_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use godot::{classes::{EditorPlugin, IEditorPlugin}, prelude::*};

use super::FluentExportPlugin;

/// Editor plugin to register tools for Fluent Translations. For internal use only.
#[derive(GodotClass)]
#[class(tool, editor_plugin, init, base=EditorPlugin)]
#[class(tool, init, base=EditorPlugin)]
pub struct FluentEditorPlugin {
export_plugin: Option<Gd<FluentExportPlugin>>,
base: Base<EditorPlugin>,
Expand Down
18 changes: 16 additions & 2 deletions rust/src/fluent/export_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use super::strip_comments;
const EXPORT_OPTION_PREFIX: &str = "fluent/";
const EXPORT_OPTION_STRIP_COMMENTS: &str = constcat!(EXPORT_OPTION_PREFIX, "strip_comments");

/// Export plugin to handle post-processing options for Fluent Translations. For internal use only.
#[derive(GodotClass)]
#[class(base=EditorExportPlugin)]
#[class(tool, base=EditorExportPlugin)]
pub struct FluentExportPlugin {
base: Base<EditorExportPlugin>,
}
Expand All @@ -20,7 +21,7 @@ impl IEditorExportPlugin for FluentExportPlugin {
}
}

fn get_export_options(&self, _platform: Gd<EditorExportPlatform>) -> Array<Dictionary> {
fn get_export_options(&self, _platform: Option<Gd<EditorExportPlatform>>) -> Array<Dictionary> {
array![dict! {
"option": dict! {
"name": GString::from(EXPORT_OPTION_STRIP_COMMENTS),
Expand All @@ -44,4 +45,17 @@ impl IEditorExportPlugin for FluentExportPlugin {
self.base_mut().add_file(path, binary, false);
}
}

fn customize_resource(&mut self, _resource: Gd<Resource>, _path: GString) -> Option<Gd<Resource>> {
None
}
fn customize_scene(&mut self, _scene: Gd<Node>, _path: GString) -> Option<Gd<Node>> {
None
}
fn get_customization_configuration_hash(&self) -> u64 {
0
}
fn get_name(&self) -> GString {
"FluentExportPlugin".into()
}
}
8 changes: 8 additions & 0 deletions rust/src/fluent/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use godot::global::Error as GdErr;

use super::{project_settings::{INVALID_MESSAGE_HANDLING_SKIP, PROJECT_SETTING_GENERATOR_INVALID_MESSAGE_HANDLING, PROJECT_SETTING_GENERATOR_LOCALES, PROJECT_SETTING_GENERATOR_PATTERNS}, FluentPackedSceneTranslationParser, FluentTranslationParser};

/// Allows generating Fluent Translation List (FTL) files by extracting keys.
///
/// For now, this class only supports [PackedScene] files and is completely loaded via Project Settings configuration.
/// It may be updated in the future to receive a proper API and editor integration.
#[derive(GodotClass)]
#[class(no_init)]
pub struct FluentGenerator {
Expand All @@ -26,6 +30,7 @@ pub type MessageGeneration = HashMap<String, String>;

#[godot_api]
impl FluentGenerator {
/// Create a new [FluentGenerator] instance using the Project Settings for configuration.
#[func]
pub fn create() -> Gd<Self> {
let project_settings = ProjectSettings::singleton();
Expand All @@ -46,6 +51,9 @@ impl FluentGenerator {
})
}

/// Generate Fluent Translation List (FTL) files, creating or updating files as necessary.
/// If a message is already translated, it will not be updated.
/// Deleted keys are currently left untouched and must be manually purged.
#[func]
pub fn generate(&self) {
// Collect source files and batched write operations.
Expand Down
1 change: 1 addition & 0 deletions rust/src/fluent/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use godot::classes::ResourceLoader;

use super::ResourceFormatLoaderFluent;

/// Singleton for handling Fluent Translation. For internal use only.
#[derive(GodotClass)]
#[class(base=Object, init)]
pub struct FluentI18nSingleton {
Expand Down
3 changes: 3 additions & 0 deletions rust/src/fluent/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use godot::global::Error as GdErr;

use super::{locale::{compute_locale, compute_message_pattern}, project_settings::*, TranslationFluent};

/// Loads Fluent Translation List (FTL) files.
///
/// This loader is already registered and does usually not need to be manually used. Use [method @GDScript.load] on a `.ftl` file instead.
#[derive(GodotClass)]
#[class(base=ResourceFormatLoader)]
pub struct ResourceFormatLoaderFluent {
Expand Down
Loading

0 comments on commit b90ab40

Please sign in to comment.