public TodoListPage() { FlowDirection = Device.FlowDirection; Title = AppResources.ApplicationTitle; listView = new ListView { RowHeight = 40 }; listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell)); listView.ItemSelected += async(sender, e) => { await Navigation.PushAsync(new TodoItemPage { BindingContext = (TodoItem)e.SelectedItem }); }; var layout = new StackLayout { Margin = new Thickness(20) }; layout.Children.Add(listView); Content = layout; var tbiAdd = new ToolbarItem("Add", "plus.png", () => { var todoItem = new TodoItem(); var todoPage = new TodoItemPage(); todoPage.BindingContext = todoItem; Navigation.PushAsync(todoPage); }, 0, 0); ToolbarItems.Add(tbiAdd); var tbiSpeak = new ToolbarItem("Speak", "chat.png", () => { var todos = App.Database.GetItemsNotDone(); var tospeak = ""; foreach (var t in todos) { tospeak += t.Name + " "; } if (tospeak == "") { tospeak = "there are no tasks to do"; } if (todos.Any()) { var s = L10n.Localize("SpeakTaskCount", AppResources.Culture); tospeak = String.Format(s, todos.Count()) + tospeak; } DependencyService.Get <ITextToSpeech>().Speak(tospeak); }, 0, 0); ToolbarItems.Add(tbiSpeak); }
public object ProvideValue(IServiceProvider serviceProvider) { if (Text == null) { return(null); } Debug.WriteLine("Provide: " + Text); // Do your translation lookup here, using whatever method you require var translated = L10n.Localize(Text, Text); return(translated); }
void OnSpeakClicked(object sender, EventArgs e) { var notDoneItems = App.Database.GetItemsNotDone(); string toSpeak = string.Empty; foreach (var item in notDoneItems) { toSpeak += item.Name + " "; } if (string.IsNullOrWhiteSpace(toSpeak)) { toSpeak = "There are no tasks to do"; } if (notDoneItems.Any()) { var s = L10n.Localize("SpeakTaskCount", AppResources.Culture); toSpeak = string.Format(s, notDoneItems.Count()) + toSpeak; } DependencyService.Get <ITextToSpeech>().Speak(toSpeak); }
public TodoItemPage() { this.SetBinding(ContentPage.TitleProperty, "Name"); NavigationPage.SetHasNavigationBar(this, true); var nameLabel = new Label(); // no Text! localized later var nameEntry = new Entry(); nameEntry.SetBinding(Entry.TextProperty, "Name"); var notesLabel = new Label(); // no Text! localized later var notesEntry = new Entry(); notesEntry.SetBinding(Entry.TextProperty, "Notes"); var doneLabel = new Label(); // no Text! localized later var doneEntry = new Switch(); doneEntry.SetBinding(Switch.IsToggledProperty, "Done"); var saveButton = new Button(); // no Text! localized later saveButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.SaveItem(todoItem); this.Navigation.PopAsync(); }; var deleteButton = new Button(); // no Text! localized later deleteButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.DeleteItem(todoItem.ID); this.Navigation.PopAsync(); }; var cancelButton = new Button(); // no Text! localized later cancelButton.Clicked += (sender, e) => { this.Navigation.PopAsync(); }; var speakButton = new Button(); // no Text! localized later speakButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; DependencyService.Get <ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes); }; // TODO: Forms Localized text using two different methods: // refer to the codebehind for AppResources.resx.designer nameLabel.Text = AppResources.NameLabel; notesLabel.Text = AppResources.NotesLabel; doneLabel.Text = AppResources.DoneLabel; // using ResourceManager saveButton.Text = AppResources.SaveButton; deleteButton.Text = L10n.Localize("DeleteButton", "Delete"); cancelButton.Text = L10n.Localize("CancelButton", "Cancel"); speakButton.Text = L10n.Localize("SpeakButton", "Speak"); // HACK: included as a 'test' for localizing the picker // currently not saved to database //var dueDateLabel = new Label { Text = "Due" }; //var dueDatePicker = new DatePicker (); Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Padding = new Thickness(20), Children = { nameLabel, nameEntry, notesLabel, notesEntry, doneLabel, doneEntry, //dueDateLabel, dueDatePicker, saveButton, deleteButton,cancelButton, speakButton } }; }
public TodoItemPage() { this.SetBinding(ContentPage.TitleProperty, "Name"); NavigationPage.SetHasNavigationBar(this, true); var nameLabel = new Label { Text = "Name" }; var nameEntry = new Entry(); nameEntry.SetBinding(Entry.TextProperty, "Name"); var notesLabel = new Label { Text = "Notes" }; var notesEntry = new Entry(); notesEntry.SetBinding(Entry.TextProperty, "Notes"); var doneLabel = new Label { Text = "Done" }; var doneEntry = new Xamarin.Forms.Switch(); doneEntry.SetBinding(Xamarin.Forms.Switch.IsToggledProperty, "Done"); var saveButton = new Button { Text = "Save" }; saveButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.SaveItem(todoItem); Navigation.PopAsync(); }; var deleteButton = new Button { Text = "Delete" }; deleteButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.DeleteItem(todoItem.ID); Navigation.PopAsync(); }; var cancelButton = new Button { Text = "Cancel" }; cancelButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; Navigation.PopAsync(); }; var speakButton = new Button { Text = "Speak" }; speakButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; DependencyService.Get <ITextToSpeech> ().Speak(todoItem.Name + " " + todoItem.Notes); }; // refer to the codebehind for AppResources.resx.designer nameLabel.Text = AppResources.NameLabel; notesLabel.Text = AppResources.NotesLabel; doneLabel.Text = AppResources.DoneLabel; // using ResourceManager saveButton.Text = AppResources.SaveButton; deleteButton.Text = L10n.Localize("DeleteButton", "Delete"); cancelButton.Text = L10n.Localize("CancelButton", "Cancel"); speakButton.Text = L10n.Localize("SpeakButton", "Speak"); Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Padding = new Thickness(20), Children = { nameLabel, nameEntry, notesLabel, notesEntry, doneLabel, doneEntry, saveButton, deleteButton,cancelButton, speakButton } }; }
public TodoListPage() { Title = AppResources.ApplicationTitle; // "Todo"; listView = new ListView { RowHeight = 40 }; listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell)); listView.ItemSelected += (sender, e) => { var todoItem = (TodoItem)e.SelectedItem; // use C# localization var todoPage = new TodoItemPage(); // use XAML localization // var todoPage = new TodoItemXaml(); todoPage.BindingContext = todoItem; Navigation.PushAsync(todoPage); }; var layout = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand }; layout.Children.Add(listView); Content = layout; var tbiAdd = new ToolbarItem("Add", "plus.png", () => { var todoItem = new TodoItem(); var todoPage = new TodoItemPage(); todoPage.BindingContext = todoItem; Navigation.PushAsync(todoPage); }, 0, 0); ToolbarItems.Add(tbiAdd); var tbiSpeak = new ToolbarItem("Speak", "chat.png", () => { var todos = App.Database.GetItemsNotDone(); var tospeak = ""; foreach (var t in todos) { tospeak += t.Name + " "; } if (tospeak == "") { tospeak = "there are no tasks to do"; } if (todos.Any()) { var s = L10n.Localize("SpeakTaskCount", "Number of tasks to do"); tospeak = String.Format(s, todos.Count()) + tospeak; } DependencyService.Get <ITextToSpeech>().Speak(tospeak); }, 0, 0); ToolbarItems.Add(tbiSpeak); }
public TodoItemPage() { FlowDirection = Device.FlowDirection; this.SetBinding(Page.TitleProperty, "Name"); NavigationPage.SetHasNavigationBar(this, true); var nameLabel = new Label(); // no Text! localized later var nameEntry = new Entry(); nameEntry.SetBinding(Entry.TextProperty, "Name"); var notesLabel = new Label(); // no Text! localized later var notesEntry = new Entry(); notesEntry.SetBinding(Entry.TextProperty, "Notes"); var doneLabel = new Label(); // no Text! localized later var doneEntry = new Switch(); doneEntry.SetBinding(Switch.IsToggledProperty, "Done"); var saveButton = new Button(); // no Text! localized later saveButton.Clicked += async(sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.SaveItem(todoItem); await Navigation.PopAsync(); }; var deleteButton = new Button(); // no Text! localized later deleteButton.Clicked += async(sender, e) => { var todoItem = (TodoItem)BindingContext; App.Database.DeleteItem(todoItem.ID); await Navigation.PopAsync(); }; var cancelButton = new Button(); // no Text! localized later cancelButton.Clicked += async(sender, e) => { await Navigation.PopAsync(); }; var speakButton = new Button(); // no Text! localized later speakButton.Clicked += (sender, e) => { var todoItem = (TodoItem)BindingContext; DependencyService.Get <ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes); }; // TODO: Forms Localized text using two different methods: // refer to the codebehind for AppResources.resx.designer nameLabel.Text = AppResources.NameLabel; notesLabel.Text = AppResources.NotesLabel; doneLabel.Text = AppResources.DoneLabel; // using ResourceManager saveButton.Text = AppResources.SaveButton; deleteButton.Text = L10n.Localize("DeleteButton", AppResources.Culture); cancelButton.Text = L10n.Localize("CancelButton", AppResources.Culture); speakButton.Text = L10n.Localize("SpeakButton", AppResources.Culture); Content = new StackLayout { Margin = new Thickness(20), Children = { nameLabel, nameEntry, notesLabel, notesEntry, doneLabel, doneEntry, saveButton, deleteButton,cancelButton, speakButton } }; }