I'm newby in the ampscript world and need you help! For a mail for different countries I have a translation dE with several languages (column = language) and the main DE with customer records. In order to personalize the mail I need to filter the mobile phone country code from the main data extension and mapp it to the translation DE since not all customers have a language! How to realize this in ampscript: if mobilePhone beginns with '+44' the language = 'EN' elseif mobilePhone beginns with '+49' the language = 'de' and so on..
You can write an IF Statement in AMPScript to generate a list of applicable language codes.
Assuming your customer's phone data is based on this List of mobile telephone prefixes by country or this List of country calling codes, then the following example will work:
%%[ SET @mobileprefix = Substring(mobilePhone,1,3) IF @mobileprefix == "+44" THEN SET @Language = "EN" ELSEIF (@mobileprefix == "+33" OR @mobileprefix == "+32") THEN SET @Language = "FR" ELSEIF @mobileprefix == "+49" THEN SET @Language = "DE" ELSE SET @Language = "EN" ENDIF SET @target_rows = LookupRows("DE_Translations","Language", @Language) ]%%
In the above sample, France and Belgium are combined using an OR statement for the Langauge FR as an example.
The default language for customers without a phone number can be set using an ELSE statement - currently set as "EN" in the above sample.
This should work for your use case, however I would encourage you to make the "Language" value a static attribute/value for each customer in your "Customers data extension" using SQL.
This will be more efficient than rendering it in AMPScript every time you send an email, and will give you the ability to let customer's specify their "preferred language" in the future.
OR Statements in AMPScript