Piranha CMS localisation - asp.net-core

How can I localize the excelent Piranha Headless CMS solution?
I want to be able to allow the user to select a language and display content in function of that selection. I just want to display two sets of pages, no globalization.
Kind regsrds,
Karel

Since the CMS itself isn't multi-lingual at this point, your best option would be to add two different site, one for each language. In the hostnames field of your site your could for example set it up like:
mydomain.com // For the default site
mydomain.com/lang // For the translated site
The downside of this would of course be having to manage two different sitemaps.
Another option would be to create a TranslationRegion where you can translate all of the base fields of the page, for example:
public class PageLocalization {
[Field]
public StringField Title { get; set; }
[Field]
public StringField NavigationTitle { get; set; }
[Field]
public StringField Keywords { get; set; }
[Field]
public TextField Description { get; set; }
}
You could also create a reusable region for HTML-content, like so:
public class HtmlLocalization {
[Field]
public HtmlField Body { get; set; }
[Field]
public HtmlField TranslatedBody { get; set; }
}
And then use these when building your page type.
[PageType(Title = "My Page")]
public class MyPage : Page<MyPage> {
[Region]
public PageLocalization PageLocalization { get; set; }
[Region]
public HtmlLocalization MainContent { get; set; }
}
With this solution you would only need one site and one sitemap, but views will have to handle which fields to use when rendering the site depending on the choosen language.
Like I mentioned earlier, there's really no built in features in Piranha CMS for multi-lingual support, but it might be added in the future. There is a feature request for it at GitHub but it's nothing that's planned for development in the near future.
Regards

Related

Confused about DTOs when reading and editing. How to desing DTO for filling the form in VUEjs app?

I am trying to develop an enterprise-level application. I have domain and application services. I have created my DTOs for multiple purposes separately. But confused about which way I should use them from the API viewpoint.
I have complex objects lets say,
public class Entity{
public int Id { get; set; }
public string Name { get; set; }
public int? ManufacturerId { get; set; }
public virtual Manufacturer Manufacturer { get; set; }
}
public class Manufacturer{
public int Id { get; set; }
public string Text { get; set; }
}
And I have corresponding DTOs designed with composition now. It was separated before.
public class EntityBaseDto{
public string Name { get; set; }
}
public class EntityReadDto : EntityBaseDto{
public string Manufacturer { get; set; }
}
public class EntityWriteDto : EntityBaseDto{
public int? ManufacturerId { get; set; }
}
Now the question is,
I have a table which is filled with List<EntityReadDto> which is clear. Before, EntityReadDto also had the ManufacturerDto as fully included with id and text. Whenever I require to edit one of the entries from the table I was able to load the dropdown selected items or list of tags etc with the ids attached to the Manufacturer objects within ReadDtos. Now it is not possible. Since I wanted to simplify the codes I just converted them to strings that are read-only. Now I have created another endpoint to get an editable version of the record when needed. Ex: EntityWriteDto will be used to fill the form when the edit is clicked on a specific item. The manipulation will be carried on that DTO and sent with the PUT type request to edit the record.
I am not sure if this approach is ok for these cases. What is the best practice for this? I have many objects related to the entities from other tables. Is it ok to make a call to get an editable version from the backend or need to have it right away in a VUEjs app?

What's the best way to go about implementing hashtag functionality in EF Core/Razor Pages?

I'm trying to implement hasthags into an application. I've configured the database already and even have a layout for how I'd like the form to look, however I'm not sure if it's possible to do what I want to do with Razor pages. I have the below classes:
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName{ get; set; }
public IList<PersonTag> PersonTags { get; set; }
}
public class Tag
{
public int TagId { get; set; }
public string TagName { get; set; }
public IList<PersonTag> PersonTags { get; set; }
}
public class PersonTag
{
public int PersonTagId { get; set; }
public int PersonId { get; set; }
public Person Person { get; set; }
public int TagId { get; set; }
public Tag Tag { get; set; }
}
And would like the form to look like this, where you see this input while editing a Person. You'd add a new hashtag by typing in the input box--hitting enter there (or pressing a button--not pictured) would create the tag in the Tag table and also create a new PersonTag relationship with the Person being edited, which would be saved on form submission. I guess the Tag could also get created on form submission if that's simpler. Clicking the "x" on one of the tags should also remove the PersonTag relationship
Is this something that's possible with razor pages? To this point I've only ever done simpler inputs (either single values or select lists), but in this case I need the user to have the option to enter free text multiple times. What kind of input would I need for these? Or would I need to do entirely special handling to pull the data on form submit, and just populate the tags with Javascript when the user adds them?

MVC4 / EF5 / Auto Increment

I'm not sure how to exactly word my question which is probably why I cannot find an example of this anywhere. I'm playing around with MVC4 & EF5 (Web API too) but I'm not sure how to proceed with the Model as I've never really had to do much with them before. I'm doing something around the Periodic Tablet of Elements and I want to make it so that I have a list built for an element with it's electron configuration. However, I'd like to have it just auto number based on the input order. How can I tell EF to auto-increment a field? Basically like a primary key field without that limitation behind it. Here's what I have so far - I'm just not sure how to proceed:
public class Elements
{
public int ElementID { get; set; }
public string Name { get; set; }
public int AtomicNumber { get; set; }
public string Symbol { get; set; }
public virtual Categories Category { get; set; }
public virtual States State { get; set; }
public virtual Occurences Occurence { get; set; }
public virtual ICollection<Configurations> Configuration { get; set; }
}
public class Categories
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
public class States
{
public int StateID { get; set; }
public string StateName { get; set; }
}
public class Occurences
{
public int OccurenceID { get; set; }
public string OccurenceName { get; set; }
}
public class Configurations
{
public int ConfigurationID { get; set; }
public int Order { get; set; }
public int Value { get; set; }
}
Looking above what I'd like is for anytime a value is added to Configurations.Order the value starts at 1 and increases with each new 'row' but only for that specific ElementID.
Does that make sense? I was looking at using Data Annotations but I couldn't find anything that matched other than a Key Field but that'd make each Order a unique number - which I don't want. I feel like I'm not expressing this correctly because of all the stuff I've been looking at to figure it out, so here's a picture! yay!
This very well could be something that is better off from a programmatic standpoint. Even though this data changes once in a blue moon, I wanted to try and do it through EF if possible just so I know how.
Thanks a ton in advance. Also, if you see any other glaring errors, by all means let me know :) I rarely get to work with this side of web dev so I'm sure there's ways to do things better.
How can I tell EF to auto-increment a field?
You can't. Not even for a simple auto-incrementing primary key. Let alone for a field that should increment in relation to other values.
The HasDatabaseGeneratedOption mapping method is not a way to tell EF how to generate key values. It tells EF if and how the database generates values for properties, so EF knows how to respond to that.
So you either have to generate the order numbers in code, or let the database do it (by a trigger, or by mapping CUD actions on Configurations to stored procedures) and tell EF that the database computes the values by HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed) in the configuration of the Order property.

Rolling my own CMS with the WCF, what should my contract be?

I'm looking to create a solution for a asp.net mvc app that displays unstructured course descriptions that have been scraped from around the web. The web server will be on a web hosting company while the description db will be on a private network, so I'd like to pass the description to the mvc app through a WCF service. For the body of the description do I just want to use a string property...
public class CourseDescription {
// data fields
public string CourseTitle { get; set; }
public int Days { get; set; }
public List<DateTime> UpcomingDates { get; set; }
// html properties
public string Keywords { get; set;}
public string HtmlDescription { get; set; }
}
... or is there a better way?
If it is unstructured text, a string is fine.

How to structure domain model when using NHibernate Search/Lucene

I am messing around with NHibernate Search and Lucene to create a searchable index of legal entities. My domain model looks somewhat like this:
[Indexed]
public abstract class LegalEntity : AggregateRoot
{
public virtual Address Address { get; set; }
}
public class Person : LegalEntity
{
public virtual string FirstNames { get; set; }
public virtual string LastName { get; set; }
}
public class Company: LegalEntity
{
public virtual string Name { get; set; }
}
public class Address : Component
{
public virtual string Street { get; set; }
public virtual string HouseNumber { get; set; }
// etc...
}
As the subclassing implies, LegalEntity is an NHibernate entity specialized as Person and Company, and Address is an NHibernate component.
Now, how would I best go about creating a really Google-like fuzzy search that includes all the fields of a LegalEntity, including those inside the Address component?
My first idea was to implement an AddressFieldBridge to help in bringing in the fields of the Address component, and then just throw in [Field] on all the fields, but then I could not find a way to construct a FuzzyQuery as a conjuntion between multiple search terms.
My next idea was to create an abstract property tagged with [Field] on LegalEntity, like so:
[Field(Index.Tokenized)]
public abstract string SearchableText { get; }
and then have Person and Company return texts that combine names and all the fields from the Address component into one string, which would then be tokenized and indexed by Lucene.
That, however, made me feel kind of icky.
I would like to learn the best and least intrusive (from a domain model perspective) way to accomplish this task - any suggestions are appreciated :)
Take a look at my question.
Andrey created patch to specify lucene stuff outside. Syntax ain't uber clean (maybe there's some progress done on this, haven't checked), but i guess it gets job done.