I have a large PHP Document in the following format:
<?php
define("TITLE","HAPPY DAYS");
define("FOOTER","This site is ok");
... 1000 more
?>
I want to translate it to Spanish.
I tried Google translate but it also translated TITLE , FOOTER which are PHP keywords and should be not translated.
Any idea how to automate it?
If my call is
API?text="TEXT HERE"
it returns
TEXT TRANSLATED
I would suggest two ways which i would prefer
Method 1 : ->Manually
You can have a table like this
S.No | Text | French_Text | Spanish_Text
1 | KNowledge | Connaissance | Conocimiento
So You will give the english value by default, then if the user chooses the some language you can set a cookie or some storage locally,
And in the header page according to the selection you will refer the French_Text or Spanish_Text. You can have as many language like this.
Or you can go to any api
Method 2 : -> Using some api
You can select an api which allows to translate with respect to div or class. So that you can have translation for the particular area that you need.
Related
I'm trying to achieve this in Codeigniter. I have got a URL like below
https://www.example.com/5474/my-first-post
I'll be processing this URL using the id and get the blog content from this id. but I don't want to show the ID in the URL.It should be like below.
https://www.example.com/my-first-post
I'm doing this because previously I was getting the blog content using the title. But that makes the website very slow when there are a lot of rows in the database (It takes around 5 seconds roughly on the local server).Where as I tried the same using the ID. I was getting the row from database using the ID. It takes very less time like say 0.0007 seconds. Any solution to this is highly appreciated.
This is too hard to do routes for each url.
add a field in your table..
ID | url | post_title
33 | hello-world | Hello World.
Then use that url text on behalf of id
convert your numeric id using base64_encode()
You can use
uri-routing
Example:
$route['my-first-post'] = 'your_controller/your_function';
For some time now I'm thinking about a nice way on how to dynamically load code in php based on database entries. I've tried to look up something related, but couldn't really find anything that answered my question(s) thoroughly. I'm using Laravel - not sure if this might be a subject to solve this particular problem.
See the following code for "example data" where I tried to give a quick overview over the database structure. So for a game, lets say we have characters that can be at a location. Any location basically looks the same. You have a form to write a message at this location - nothing fancy. But then there might be some exceptions. For example you might have a location, that implements some more logic such as listing all online characters (+ showing their current location's name.). Or a location might show some other additional content.
This is what I came up with so far, but neither seems optimal:
Creating different tables for different types of locations (this seems very bad to me actually).
Create another table, f.e. modules, and have a many-to-many relationship with the location table. the modules table would then have entries for a location that tell the application what to "execute". F.e., a location might have the entries thread, for allowing to post messages, list, for showing an overview of online characters and their locations, trader, to allow some gameplay mechanics etc.
To me the second option seems to be kind of the right way of achieving what I want to achieve. I would have classes, functions etc. that would represent these modules. But it too seems very hardcode-y. Meaning, that for one in the code behind I would have to distinct between the values which I might or might not want to change in the future, which then would require a lot of refactoring. Because I have to distinct between strings, this design is prone to typos and what not...
character:
id | location_id (nullable) | name
---------------------------------
1 | 1 | Test
location:
id | name
----------------
1 | Location #1
2 | Online Characters
For the above presented version I would add:
modules:
id | name
---------
1 | thread
2 | list
3 | trader
location_modules:
location_id | modules_id
------------------------
1 | 1
1 | 3
2 | 2
I have made a CMS using PHP and MYSQL for the back-end. The problem is, I'd like to have the site available in multiple languages; So I've already translated the CMS itself and put it in files like:
en.ini
nl.ini
Which works fine for the CMS' contents itself, like the Administration etc. The actual problem occurs when I try to translate the website further: The blogposts and pages are stored in a database, so they're dynamic. My pages table's structure looks like this:
urlname | name | id | content | position | hidden | redirect | type | permission
So, if I were to translate a page into, for example, Dutch, I don't want to create a new table called pages_nl for example, because most of the information would be the same as the other table.
I could add a row which contains the page's available languages, and make php read the array and parse if the current $lang matches one of the page's available languages, and then read the content_nl and name_nl row as an example.
The same problem would occur with my blog posts, and I have searched for a solution, but most results were for specific CMSs and just plugins.
I'm asking what would be the best way (and database structure) to store multilingual pages/posts, where languages could be added dynamically and have a fallback on the original content if there's no translated version available.
Basically you add a lang-key to your database
urlname | name | id | content | position | hidden | redirect | type | permission | lang
Now lets say a request comes for a page with 5 content elements in it. Your CMS first search for the entries with the specific lang-code, for example nl. If it dont find an entry with the language code it falls back to the default language and take that entry.
Let say you have translated Content 1, 3 and 5:
Content 1 Content 1 nl
Content 2
Content 3 Content 3 nl
Content 4
Content 5 Content 5 nl
Result:
Content 1 nl
Content 2
Content 3 nl
Content 4
Content 5 nl
Another way would be to do the translation in the template files (like magento does it).
In magento you have something like that:
"Hello, this is the " . $this->__("English") . " page"
And translation files. For example lang.nl:
"English", "Dutch"
In this case you will have only 1 Content Element, but you will wrap every element that shall be translated. This also works with images and everything you want. You can also abstract this wrapper to work in a backend RTE-Editor. For example, you will write Hello, this is the English page in your backend then mark Englishand click the translation button. This will add a Tag around English and when you render the content you scan for this tags and replace it if you find any translation for this string in the requested language.
I'm currently have around 100 rows in a table on my website, which include a URL and few sets of numbers pulled from a database on my server. What I would like to do is to dynamically create pages based on a cell of each row, which would contain data pulled from the same database. For example, each row (displayed in the table) would look like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5
Inside my database however, each row is like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5 | Description (large body of text) | LargeImage (url)
Since I have so many entries, I would like to be able to have some way to generate the pages based on the name of the row in the database (it would take too long to make each page individually, and I will be updating this table frequently with content), so I can display more of the information out of the database row (the description, largeimage etc) that I wouldn't be able to fit into the table.
Are there any plugins for Wordpress that can do this, and if not, how would I go about doing this in PHP?
I'm not sure how to best integrate this into WP, but it's fairly straightforward in PHP. You just have a file like mypage.php?id={#} where the # is the individual record's ID. You pull the ID using GET ($id = $_GET["id"];) and then run an SQL query with it as the WHERE, take the results and populate the page with that row of data. Then, using .htaccess, you can do what WP does and make this look like a URL (ie. mypage/2/).
You can create the custom page by using a method like this for example.
You could integrate this into WP by creating a separate file (other than single.php, for example) that would run this PHP script, but include the WP header and footer to make it fit into the theme. However, this wouldn't really be fully integrated into single.php and therefore wouldn't appear in the posts section in the admin or anything. Is that a requirement?
Okay, I'll lay this out simply:
I have one database that has content in it but I need to set up a conditon where if the user has selected Britain instead of the U.S. or vice versa -- some content will not show. This condition can be applied via a checkbox in the backend like so.
"Hello, I'm a paragraph" show in [x] Britian [x] U.S.
I'm not looking into actual IP Addresses or anything of that sort as the site will simply redirect to root/uk or root/us subfolders upon the user's selection on the index page. What kind of a unique parameter would I have incorporate in the db or php?
Thank You!
Add a column in the database display_content, make it a EMUN and set the values to 'britain','usa','all' then make the adjustments in your code to check for Britain/USA. you can either choose to display all, Britain or USA.
That's an interesting problem. Because although it's language oriented, it's not actually I18N related - you're talking about deny access to content based on a language preference, not displaying localized content.
Here's one idea: use a permission model
Create two permissions such as "read-enUS-content" and "read-enGB-content"
Based on the user's selection, grant them the correct permission for the length of their session (which you can persist if you wish via cookies or user prefs)
It would then be the responsibility of the application to allow/deny the content based on their permissions.
Then the question becomes, how do you connect content to permissions? There are a multitude of ways, but one approach is a bitmask column.
00
||
|+--- Read enUS bit
+---- Read enGB bit
Which might look like this when implemented
Articles
+----+---------+-----------------+
| id | content | read_perm_level |
+----+---------+-----------------+
| 1 | foo | 1 |
| 2 | bar | 2 |
| 3 | baz | 3 |
+----+---------+-----------------+
This means that 'foo' is only readable by enUS, 'bar' is only readable by enGB, and 'baz' is readable by all.
But you could also do a full permission's table and connect the content to it that way.
The most straightforward model for this would be an associative table in your database. You'd thus have:
paragraphs (paragraph_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, paragraph_text TEXT, ...) ENGINE=InnoDB;
paragraph_countries (paragraph_id INT UNSIGNED, country_code CHAR(2)) ENGINE=Innodb;
When saving the paragraph settings, perform these steps:
BEGIN WORK (to start a transaction)
DELETE FROM paragraph_countries WHERE paragraph_id = ...
(foreach checked country): INSERT INTO paragraph_countries (...)
COMMIT (to commit the transaction)
To select paragraphs relevant to the current country, simply JOIN to the associated table with the appropriate country code.