Skip to content

Commit

Permalink
Merge pull request #131 from FmgLib/130-columndefinitioncollectionext…
Browse files Browse the repository at this point in the history
…ension-and-rowdefinitioncollectionextension-add

130 columndefinitioncollectionextension and rowdefinitioncollectionextension add
  • Loading branch information
gonultasmf authored Sep 27, 2024
2 parents b1c4a4c + c7dd05f commit f2353a2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 3 deletions.
84 changes: 81 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Getting Started
# Getting Started

### Creating a new FmgLib.MauiMarkup project from CLI

Expand Down Expand Up @@ -113,15 +113,17 @@ This would set the `AbsoluteLayout.LayoutBounds` attached property to the specif

## Attached properties list

| Maui bağlı özelliği | FmgLib.MauiMarkup metodu |
| Maui Attached Prop | FmgLib.MauiMarkup method |
|-|-|
|`FlyoutBase.ContextFlyout`|`ContextFlyout()`|
|`Grid.Column`|`Column()`|
|`Grid.Row`|`Row()`|
|`Grid.ColumnSpan`|`ColumnSpan()`|
|`Grid.RowSpan`|`RowSpan()`|
||`Span(column, row)`|
|`Grid.ColumnSpan`+`Grid.RowSpan`|`Span(column, row)`|
|`VisualStateManager.VisualStateGroups`|`VisualStateGroups()`|
|`RadioButtonGroup.GroupName`|`RadioButtonGroupGroupName()`|
|`RadioButtonGroup.SelectedValue`|`RadioButtonGroupSelectedValue()`|
|`AbsoluteLayout.LayoutFlags`|`AbsoluteLayoutFlags()`|
|`AbsoluteLayout.LayoutBounds`|`AbsoluteLayoutBounds()`|
|`BindableLayout.EmptyView`|`BindableLayoutEmptyView()`|
Expand Down Expand Up @@ -1356,6 +1358,82 @@ new Button()
.FormViewIsSubmitButton(true)
```

# Localization

In the MauiProgram.cs file,
```CSharp
builder
.UseMauiApp<App>()
.UseMauiMarkupLocalization();
```
should be added.

In your main project you should have a language file of type json. The translation will be read from this file and imported.
If you do not specify the path to the file(s) in the parameter (
```CSharp
builder
.UseMauiApp<App>()
.UseMauiMarkupLocalization();
//.UseMauiMarkupLocalization(defaultLang:"en-US"); // or
//.UseMauiMarkupLocalization(defaultLang:"en-US", "Loc1.json", "Loc2.json"); // or
```
), will look for a json file named `Localization.json` in the home directory.

if you give one or more parameters like
```CSharp
builder
.UseMauiApp<App>()
.UseMauiMarkupLocalization("Localization1.json", "Localization2.json", "/Languages/Temp1.json");
```

it will read json files in given file paths.

**The critical point here is to select ```Build Action: MauiAsset``` for json files.**

Proper json format:

```json
{
"Hello": {
"tr-TR": "Merhaba Dünya!",
"en-US": "Hello World!"
},
"Msg": {
"tr-TR": "Deneme amaçlı yapılmıştır.",
"en-US": "It was made for testing purposes."
}
}
```

Instead of 'keyWord' keywords, you can use any word or phrase(s) you want. You don't have any Regex limitations.

You can also change the 'tr-TR' and 'en-US' language keys with words or sentences as you wish. But it is recommended to use expressions such as 'en-US', 'tr-TR', 'fr-FR'.

You can simply use
```CSharp
new Label()
.Text(e => e.Translate("Hello"))
.FontSize(32)
.CenterHorizontal()
.SemanticHeadingLevel(SemanticHeadingLevel.Level1),

new Label()
.Text(e => e.Translate("Msg"))
.FontSize(18)
.CenterHorizontal()
.SemanticDescription(e => e.Translate("Msg"))
.SemanticHeadingLevel(SemanticHeadingLevel.Level1)
```
in the code.

To change the current language, you can proceed as follows:
```csharp
Translator.Instance.ChangeCulture(CultureInfo.GetCultureInfo("en-US"));
//OR
Translator.Instance.ChangeCulture(CultureInfo.GetCultureInfo("tr-TR"));
```


# General Example Code

```csharp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace FmgLib.MauiMarkup;

public static partial class ColumnDefinitionCollectionExtension
{
public static ColumnDefinitionCollection Auto(this ColumnDefinitionCollection self, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new ColumnDefinition(new GridLength(0.0, GridUnitType.Auto)));
}

return self;
}

public static ColumnDefinitionCollection Star(this ColumnDefinitionCollection self, double width = 1.0, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new ColumnDefinition(new GridLength(width, GridUnitType.Star)));
}

return self;
}

public static ColumnDefinitionCollection Absolute(this ColumnDefinitionCollection self, double width, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new ColumnDefinition(new GridLength(width, GridUnitType.Absolute)));
}

return self;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace FmgLib.MauiMarkup;

public static partial class RowDefinitionCollectionExtension
{
public static RowDefinitionCollection Auto(this RowDefinitionCollection self, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new RowDefinition(new GridLength(0.0, GridUnitType.Auto)));
}

return self;
}

public static RowDefinitionCollection Star(this RowDefinitionCollection self, double height = 1.0, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new RowDefinition(new GridLength(height, GridUnitType.Star)));
}

return self;
}

public static RowDefinitionCollection Absolute(this RowDefinitionCollection self, double height, int count = 1)
{
for (int i = 0; i < count; i++)
{
self.Add(new RowDefinition(new GridLength(height, GridUnitType.Absolute)));
}

return self;
}
}

0 comments on commit f2353a2

Please sign in to comment.